如何将数据从视图传递到控制器?请解释如何将ID
传递给AAA
?
我有模特:
public class ABCDE
{
public int ID { get; set; }
public string Name { get; set; }
public int Surname { get; set; }
public List<SelectListItem> MMM { get; set; }
}
我的观点:
@model IList<Jednoslad.Models.ABCDE>
@{
ViewBag.Title = "title";
Layout = "~/Views/Layout/_Layout.cshtml";
}
@foreach (var m in Model)
{
using (Html.BeginForm("AAA", "BBB"))
{
<div class="moto">
<h1>@m.ID</h1>
<h2>@m.Name</h2>
<input type="submit" name="model" value="AAA"/>
</div>
}
}
我的控制器:
[HttpPost]
public ActionResult AAA(ABCDE model)
{
return View();
}
答案 0 :(得分:1)
使用Html.EditorFor()
using (Html.BeginForm("AAA", "BBB"))
{
<div class="moto">
<h1>@Html.EditorFor(m => m.ID)</hi>
<h2>@Html.EditorFor(m =>m.Name)</h2>
<input type="submit" name="model" value="AAA"/>
</div>
}