查看
<div id="model">
@foreach (var item in Model)
{
<span>File Name: @item.Name</span><br />
<span>File Name: @item.Path</span><br />
}
</div>
<input type="submit" name="send" value="Send" id="btnSend" />
控制器
public ActionResult Send(SendDetails details)
{
//some code here
}
单击按钮时如何将模型从视图传递到控制器 提交?
答案 0 :(得分:0)
您需要在视图中创建表单,然后提交。
查看强>
@model YourModel
@using (Html.BeginForm("Send", "ControllerName", FormMethod.Post))
{
@Html.EditorFor(model => model.Name)
<button type="submit">Save</button>
}
<强>控制器强>
public ActionResult Send(YourModel model)
{
//some code here
}
答案 1 :(得分:0)
使用以下
@model yourmodel (with path) then use form
@using (Html.BeginForm("ActionName", "ControllerName", FormMethod.Post))
{
<div id="myId">
@foreach (var item in Model)
{
<span>File Name: @Html.EditorFor(item=> item.Name)</span>
<br />
<span>File Name: @Html.EditorFor(item=> item.Path)</span>
<br />
}
</div>
<input type="submit" name="send" value="Send" id="btnSend" />
}