MVC Redirection to another page result error 404 resource not found
I am trying to redirect to another page resulting error 404 unable to solve
My view page UserDashBoard.cshtml
"having code,
<fieldset >
<legend > User DashBoard </legend>
@if(Session["UserName"] != null)
{ <text >
Welcome @Session["UserName"].ToString() </text>
}
@using (Html.BeginForm("GetSurvey", "DashboardController"))
{
<input type="submit" value="Some text" />
}
</fieldset>
I want to redirect to page GetSurvey.cshtml
with controller DashboardController.cs
GetSurvey
is like,
@model List<SelectListItem>
@{
ViewBag.Title = "GetSurvey";
}
<h2>Survey List</h2>
<fieldset>
<legend> User DashBoard </legend>
@using (Html.BeginForm("GetSurvey", "DashboardController", FormMethod.Post))
{
@Html.DropDownList("ddlCustomers", Model)
<br />
<br />
<input type="submit" value="Submit" />
}
</fieldset>
and DashboardController
is,
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace Survey.Controllers
{
public class DashboardController : Controller
{
//
// GET: /Dashboard/
public ActionResult GetSurvey()
{
List<SelectListItem> customerList = Survey();
return View(customerList);
// return View();
}
public ActionResult GetSurvey(string ddlCustomers)
{
List<SelectListItem> customerList = Survey();
if (!string.IsNullOrEmpty(ddlCustomers))
{
SelectListItem selectedItem = customerList.Find(p => p.Value == ddlCustomers);
ViewBag.Message = "Name: " + selectedItem.Text;
ViewBag.Message += "\nID: " + selectedItem.Value;
}
return View(customerList);
}
private static List<SelectListItem> Survey()
{
SurveyAppEntities ObjectSur=new SurveyAppEntities();
List<SelectListItem> customerList = (from p in ObjectSur.Surveys.AsEnumerable()
select new SelectListItem
{
Text = p.Title,
Value = p.ID.ToString()
}).ToList();
return customerList;
}
}
}
I don't know why it is not redirecting to page mentioned above more over I had same issue when I start project as I rename the HomeController
name.
ROUTES:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Login", id = UrlParameter.Optional }
);
}
c# asp.net-mvc asp.net-mvc-4 asp.net-mvc-3 model-view-controller
add a comment |
I am trying to redirect to another page resulting error 404 unable to solve
My view page UserDashBoard.cshtml
"having code,
<fieldset >
<legend > User DashBoard </legend>
@if(Session["UserName"] != null)
{ <text >
Welcome @Session["UserName"].ToString() </text>
}
@using (Html.BeginForm("GetSurvey", "DashboardController"))
{
<input type="submit" value="Some text" />
}
</fieldset>
I want to redirect to page GetSurvey.cshtml
with controller DashboardController.cs
GetSurvey
is like,
@model List<SelectListItem>
@{
ViewBag.Title = "GetSurvey";
}
<h2>Survey List</h2>
<fieldset>
<legend> User DashBoard </legend>
@using (Html.BeginForm("GetSurvey", "DashboardController", FormMethod.Post))
{
@Html.DropDownList("ddlCustomers", Model)
<br />
<br />
<input type="submit" value="Submit" />
}
</fieldset>
and DashboardController
is,
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace Survey.Controllers
{
public class DashboardController : Controller
{
//
// GET: /Dashboard/
public ActionResult GetSurvey()
{
List<SelectListItem> customerList = Survey();
return View(customerList);
// return View();
}
public ActionResult GetSurvey(string ddlCustomers)
{
List<SelectListItem> customerList = Survey();
if (!string.IsNullOrEmpty(ddlCustomers))
{
SelectListItem selectedItem = customerList.Find(p => p.Value == ddlCustomers);
ViewBag.Message = "Name: " + selectedItem.Text;
ViewBag.Message += "\nID: " + selectedItem.Value;
}
return View(customerList);
}
private static List<SelectListItem> Survey()
{
SurveyAppEntities ObjectSur=new SurveyAppEntities();
List<SelectListItem> customerList = (from p in ObjectSur.Surveys.AsEnumerable()
select new SelectListItem
{
Text = p.Title,
Value = p.ID.ToString()
}).ToList();
return customerList;
}
}
}
I don't know why it is not redirecting to page mentioned above more over I had same issue when I start project as I rename the HomeController
name.
ROUTES:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Login", id = UrlParameter.Optional }
);
}
c# asp.net-mvc asp.net-mvc-4 asp.net-mvc-3 model-view-controller
its your routes, please post your routes
– mahlatse
Nov 23 '18 at 15:10
i have updated post with my routes
– john
Nov 23 '18 at 15:21
Your forms usePOST
. Your controller only handlesGET
.
– GSerg
Nov 23 '18 at 15:28
add a comment |
I am trying to redirect to another page resulting error 404 unable to solve
My view page UserDashBoard.cshtml
"having code,
<fieldset >
<legend > User DashBoard </legend>
@if(Session["UserName"] != null)
{ <text >
Welcome @Session["UserName"].ToString() </text>
}
@using (Html.BeginForm("GetSurvey", "DashboardController"))
{
<input type="submit" value="Some text" />
}
</fieldset>
I want to redirect to page GetSurvey.cshtml
with controller DashboardController.cs
GetSurvey
is like,
@model List<SelectListItem>
@{
ViewBag.Title = "GetSurvey";
}
<h2>Survey List</h2>
<fieldset>
<legend> User DashBoard </legend>
@using (Html.BeginForm("GetSurvey", "DashboardController", FormMethod.Post))
{
@Html.DropDownList("ddlCustomers", Model)
<br />
<br />
<input type="submit" value="Submit" />
}
</fieldset>
and DashboardController
is,
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace Survey.Controllers
{
public class DashboardController : Controller
{
//
// GET: /Dashboard/
public ActionResult GetSurvey()
{
List<SelectListItem> customerList = Survey();
return View(customerList);
// return View();
}
public ActionResult GetSurvey(string ddlCustomers)
{
List<SelectListItem> customerList = Survey();
if (!string.IsNullOrEmpty(ddlCustomers))
{
SelectListItem selectedItem = customerList.Find(p => p.Value == ddlCustomers);
ViewBag.Message = "Name: " + selectedItem.Text;
ViewBag.Message += "\nID: " + selectedItem.Value;
}
return View(customerList);
}
private static List<SelectListItem> Survey()
{
SurveyAppEntities ObjectSur=new SurveyAppEntities();
List<SelectListItem> customerList = (from p in ObjectSur.Surveys.AsEnumerable()
select new SelectListItem
{
Text = p.Title,
Value = p.ID.ToString()
}).ToList();
return customerList;
}
}
}
I don't know why it is not redirecting to page mentioned above more over I had same issue when I start project as I rename the HomeController
name.
ROUTES:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Login", id = UrlParameter.Optional }
);
}
c# asp.net-mvc asp.net-mvc-4 asp.net-mvc-3 model-view-controller
I am trying to redirect to another page resulting error 404 unable to solve
My view page UserDashBoard.cshtml
"having code,
<fieldset >
<legend > User DashBoard </legend>
@if(Session["UserName"] != null)
{ <text >
Welcome @Session["UserName"].ToString() </text>
}
@using (Html.BeginForm("GetSurvey", "DashboardController"))
{
<input type="submit" value="Some text" />
}
</fieldset>
I want to redirect to page GetSurvey.cshtml
with controller DashboardController.cs
GetSurvey
is like,
@model List<SelectListItem>
@{
ViewBag.Title = "GetSurvey";
}
<h2>Survey List</h2>
<fieldset>
<legend> User DashBoard </legend>
@using (Html.BeginForm("GetSurvey", "DashboardController", FormMethod.Post))
{
@Html.DropDownList("ddlCustomers", Model)
<br />
<br />
<input type="submit" value="Submit" />
}
</fieldset>
and DashboardController
is,
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace Survey.Controllers
{
public class DashboardController : Controller
{
//
// GET: /Dashboard/
public ActionResult GetSurvey()
{
List<SelectListItem> customerList = Survey();
return View(customerList);
// return View();
}
public ActionResult GetSurvey(string ddlCustomers)
{
List<SelectListItem> customerList = Survey();
if (!string.IsNullOrEmpty(ddlCustomers))
{
SelectListItem selectedItem = customerList.Find(p => p.Value == ddlCustomers);
ViewBag.Message = "Name: " + selectedItem.Text;
ViewBag.Message += "\nID: " + selectedItem.Value;
}
return View(customerList);
}
private static List<SelectListItem> Survey()
{
SurveyAppEntities ObjectSur=new SurveyAppEntities();
List<SelectListItem> customerList = (from p in ObjectSur.Surveys.AsEnumerable()
select new SelectListItem
{
Text = p.Title,
Value = p.ID.ToString()
}).ToList();
return customerList;
}
}
}
I don't know why it is not redirecting to page mentioned above more over I had same issue when I start project as I rename the HomeController
name.
ROUTES:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Login", id = UrlParameter.Optional }
);
}
c# asp.net-mvc asp.net-mvc-4 asp.net-mvc-3 model-view-controller
c# asp.net-mvc asp.net-mvc-4 asp.net-mvc-3 model-view-controller
edited Nov 23 '18 at 15:26
GSerg
58.9k14101219
58.9k14101219
asked Nov 23 '18 at 15:01
john
306
306
its your routes, please post your routes
– mahlatse
Nov 23 '18 at 15:10
i have updated post with my routes
– john
Nov 23 '18 at 15:21
Your forms usePOST
. Your controller only handlesGET
.
– GSerg
Nov 23 '18 at 15:28
add a comment |
its your routes, please post your routes
– mahlatse
Nov 23 '18 at 15:10
i have updated post with my routes
– john
Nov 23 '18 at 15:21
Your forms usePOST
. Your controller only handlesGET
.
– GSerg
Nov 23 '18 at 15:28
its your routes, please post your routes
– mahlatse
Nov 23 '18 at 15:10
its your routes, please post your routes
– mahlatse
Nov 23 '18 at 15:10
i have updated post with my routes
– john
Nov 23 '18 at 15:21
i have updated post with my routes
– john
Nov 23 '18 at 15:21
Your forms use
POST
. Your controller only handles GET
.– GSerg
Nov 23 '18 at 15:28
Your forms use
POST
. Your controller only handles GET
.– GSerg
Nov 23 '18 at 15:28
add a comment |
1 Answer
1
active
oldest
votes
Here is a simple way to check what is hapenning in your application.
A few tool exist on the internet for logging HTTP/HTTPS tracffic, one such too is fiddler, when browsing to a link on your server, you can see what data is being sent and what URL is being requested from your project.
To make it capture local data, you need to go in your project settings, and the specific URL that is presented, just append .fiddler after localhost.
e.g http://localhost.fiddler:4444/MyTestApp
The above will provide you with more data when debugging your application.
for now, just remove the Controller part from DashboardController in your view, that should now point to the correct URL, also please not that you need to Decorate your GetSurvey method with [POST] as GET is implied by default, you can override this behavior by using an overload of the @Html.BeginForm method.
@using (Html.BeginForm("someAction", "someController", FormMethod.Get))
{
...
}
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53448953%2fmvc-redirection-to-another-page-result-error-404-resource-not-found%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Here is a simple way to check what is hapenning in your application.
A few tool exist on the internet for logging HTTP/HTTPS tracffic, one such too is fiddler, when browsing to a link on your server, you can see what data is being sent and what URL is being requested from your project.
To make it capture local data, you need to go in your project settings, and the specific URL that is presented, just append .fiddler after localhost.
e.g http://localhost.fiddler:4444/MyTestApp
The above will provide you with more data when debugging your application.
for now, just remove the Controller part from DashboardController in your view, that should now point to the correct URL, also please not that you need to Decorate your GetSurvey method with [POST] as GET is implied by default, you can override this behavior by using an overload of the @Html.BeginForm method.
@using (Html.BeginForm("someAction", "someController", FormMethod.Get))
{
...
}
add a comment |
Here is a simple way to check what is hapenning in your application.
A few tool exist on the internet for logging HTTP/HTTPS tracffic, one such too is fiddler, when browsing to a link on your server, you can see what data is being sent and what URL is being requested from your project.
To make it capture local data, you need to go in your project settings, and the specific URL that is presented, just append .fiddler after localhost.
e.g http://localhost.fiddler:4444/MyTestApp
The above will provide you with more data when debugging your application.
for now, just remove the Controller part from DashboardController in your view, that should now point to the correct URL, also please not that you need to Decorate your GetSurvey method with [POST] as GET is implied by default, you can override this behavior by using an overload of the @Html.BeginForm method.
@using (Html.BeginForm("someAction", "someController", FormMethod.Get))
{
...
}
add a comment |
Here is a simple way to check what is hapenning in your application.
A few tool exist on the internet for logging HTTP/HTTPS tracffic, one such too is fiddler, when browsing to a link on your server, you can see what data is being sent and what URL is being requested from your project.
To make it capture local data, you need to go in your project settings, and the specific URL that is presented, just append .fiddler after localhost.
e.g http://localhost.fiddler:4444/MyTestApp
The above will provide you with more data when debugging your application.
for now, just remove the Controller part from DashboardController in your view, that should now point to the correct URL, also please not that you need to Decorate your GetSurvey method with [POST] as GET is implied by default, you can override this behavior by using an overload of the @Html.BeginForm method.
@using (Html.BeginForm("someAction", "someController", FormMethod.Get))
{
...
}
Here is a simple way to check what is hapenning in your application.
A few tool exist on the internet for logging HTTP/HTTPS tracffic, one such too is fiddler, when browsing to a link on your server, you can see what data is being sent and what URL is being requested from your project.
To make it capture local data, you need to go in your project settings, and the specific URL that is presented, just append .fiddler after localhost.
e.g http://localhost.fiddler:4444/MyTestApp
The above will provide you with more data when debugging your application.
for now, just remove the Controller part from DashboardController in your view, that should now point to the correct URL, also please not that you need to Decorate your GetSurvey method with [POST] as GET is implied by default, you can override this behavior by using an overload of the @Html.BeginForm method.
@using (Html.BeginForm("someAction", "someController", FormMethod.Get))
{
...
}
answered Nov 23 '18 at 15:30
mahlatse
791517
791517
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53448953%2fmvc-redirection-to-another-page-result-error-404-resource-not-found%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
its your routes, please post your routes
– mahlatse
Nov 23 '18 at 15:10
i have updated post with my routes
– john
Nov 23 '18 at 15:21
Your forms use
POST
. Your controller only handlesGET
.– GSerg
Nov 23 '18 at 15:28