我正在學習ASP.NET MVC。我正在嘗試捕獲表單上的模型數據,但模型顯示爲空。模型未在表單發佈過程中填充ASP.NET MVC
這裏是我的模型
public class SampleModel
{
public int ID { get; set; }
public string Name { get; set; }
public string CRUDOperation { get; set; }
}
這是我的看法
@model IEnumerable<SampleModel>
@using (Html.BeginForm("SubmitUpdateGridRow", "GridView", FormMethod.Post, new {value = "form" }))
{
@Html.AntiForgeryToken()
<table class="table table-bordered">
<tr>
<th>
@Html.Label("CRUD Actions")
</th>
<th>
@Html.DisplayNameFor(model => model.ID)
</th>
<th>
@Html.DisplayNameFor(model => model.Name)
</th>
</tr>
@foreach (SampleModel Row in Model)
{
<tr>
@if (Row.CRUDOperation == "Select")
{
<td>
@Html.ActionLink("Update", "UpdateGridRow", "GridView", Row, new { @title = "U: Update Operation of CRUD" }) |
@Html.ActionLink("Edit", "EditGridRow", "GridView", new { id = Row.BGID }, new { @title = "U: Update Operation of CRUD" }) |
@Html.ActionLink("Delete", "DeleteGridRow", "GridView", new { id = Row.BGID }, new { @title = "D: Delete Operation of CRUD" }) |
@Html.ActionLink("Details", "DetailsGridRow", "GridView", new { id = Row.BGID }, new { @title = "Form level view for details" })
</td>
<td>
@Row.ID
</td>
<td>
@Row.Name
</td>
}
else if (Row.CRUDOperation == "Edit")
{
<td>
@Html.HiddenFor(ID => Row.ID)
@Html.HiddenFor(CRUDOperation => Row.CRUDOperation)
@Row.BGID
</td>
<td>
@Html.EditorFor(Name => Row.Name)
</td>
<td>
<input type="submit" value="Update" id="UpdateSubmit" />
@Html.ActionLink("Edit", "EditGridRow", "GridView", new { id = Row.ID }, new { @title = "U: Update Operation of CRUD" }) |
@Html.ActionLink("Reset", "ResetGridRow", "GridView", new { id = Row.ID }, new { @title = "R: Reset Operation of CRUD" })
</td>
}
</tr>
@*<tr>
@if (Row.CRUDOperation == "Edit")
{
EditRow(Row);
}
else
{
DisplayRow(Row);
}
</tr>*@
//Row.CRUDOperation.Equals("Edit") ? EditRow(Row) : DisplayRow(Row);
}
</table>
}
這裏是我的控制器
public class GridViewController : Controller
{
[HttpPost]
public ActionResult SubmitUpdateGridRow(FormCollection FC, SampleModel VM)
{
string str = (string)FC.GetValue("Row.Name").AttemptedValue;
......
}
}
我能得到從形式收集的值,但我模型是空的。
在此先感謝。
PS:我想找到只與服務器端腳本的解決方案,不想使用JavaScript,JQuery的
如何U [R從輸入型提交烏爾提交或輸入型按鈕? –