根据 ASp.NET mvc 中的下拉信息重定向页面
Redirect Page based on dropdown information in ASp.NET mvc
我有一个下拉控件有两种类型的值 'Contractor' 和 'Full time',根据下拉选择相关控件将显示。
Now when i click on the submit button i have to redirect to different action method (i.e) when 'Contractor' is selected it should redirect to AddContractor() else it should redirect to Full time along with the filled信息。
如何使用单个 Html.Beginform()
实现
好的,你可以这样做:
观看:
@{
List<SelectListItem> items = new List<SelectListItem>();
items.Add(new SelectListItem { Text = "Contractor", Value = "0" });
items.Add(new SelectListItem { Text = "Full time", Value = "1" });
}
@using (Html.BeginForm("Go", "Home", FormMethod.Post))
{
@Html.DropDownList("Example", items)
<input type="submit" value="Submit" />
}
<p>Value selected: @ViewBag.Info</p>
在控制器上:
[HttpPost]
[AllowAnonymous]
public ActionResult Go(int example)
{
if (example != null)
{
if (example == 0)
{
return RedirectToAction("AddContractor", new { info = example});
}
else
{
return RedirectToAction("Other", new {info = example});
}
}
return View("Index");
}
public ActionResult AddContractor(int info)
{
ViewBag.Info = info;
return View("Index");
}
public ActionResult Other(int info)
{
ViewBag.Info = info;
return View("Index");
}
您可以为您的项目使用其他视图和其他信息。我只是编写示例来重定向操作和模型信息。
希望能帮到你:)
我有一个下拉控件有两种类型的值 'Contractor' 和 'Full time',根据下拉选择相关控件将显示。
Now when i click on the submit button i have to redirect to different action method (i.e) when 'Contractor' is selected it should redirect to AddContractor() else it should redirect to Full time along with the filled信息。
如何使用单个 Html.Beginform()
实现好的,你可以这样做:
观看:
@{
List<SelectListItem> items = new List<SelectListItem>();
items.Add(new SelectListItem { Text = "Contractor", Value = "0" });
items.Add(new SelectListItem { Text = "Full time", Value = "1" });
}
@using (Html.BeginForm("Go", "Home", FormMethod.Post))
{
@Html.DropDownList("Example", items)
<input type="submit" value="Submit" />
}
<p>Value selected: @ViewBag.Info</p>
在控制器上:
[HttpPost]
[AllowAnonymous]
public ActionResult Go(int example)
{
if (example != null)
{
if (example == 0)
{
return RedirectToAction("AddContractor", new { info = example});
}
else
{
return RedirectToAction("Other", new {info = example});
}
}
return View("Index");
}
public ActionResult AddContractor(int info)
{
ViewBag.Info = info;
return View("Index");
}
public ActionResult Other(int info)
{
ViewBag.Info = info;
return View("Index");
}
您可以为您的项目使用其他视图和其他信息。我只是编写示例来重定向操作和模型信息。
希望能帮到你:)