Я пытаюсь перенаправить на другую страницу, в результате чего ошибка 404 не удается решить
Моя страница просмотра UserDashBoard.cshtml
"с кодом,
<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>
Я хочу перенаправить на страницу GetSurvey.cshtml
с контроллером DashboardController.cs
GetSurvey
похоже,
@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>
и DashboardController
,
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;
}
}
}
Я не знаю, почемуболее не перенаправляя на страницу, упомянутую выше, у меня возникла та же проблема при запуске проекта, когда я переименовывал имя HomeController
.
МАРШРУТЫ:
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 }
);
}