Asp.net mvc 索引帖子未将整个模型返回控制器?
我试图在表单提交时将整个模型数据返回到索引帖子。它只返回传入URL参数的ID。为什么?Asp.net mvc 索引帖子未将整个模型返回控制器?,asp.net-mvc,razor,asp.net-mvc-4,Asp.net Mvc,Razor,Asp.net Mvc 4,我试图在表单提交时将整个模型数据返回到索引帖子。它只返回传入URL参数的ID。为什么? @using Volunteer.BootstrapSupport @model IEnumerable<Volunteer.Models.Activity> @using (Html.BeginForm()) { <h2>Member Volunteering List </h2> <div> <button t
@using Volunteer.BootstrapSupport
@model IEnumerable<Volunteer.Models.Activity>
@using (Html.BeginForm())
{
<h2>Member Volunteering List </h2>
<div>
<button type="submit" class="btn btn-primary" >New Activity</button>
</div>
<table id="volunteerlist" class="table table-striped table-bordered table-hover .table-condensed">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.Committee.Name)
</th>
<th>
@Html.DisplayNameFor(model => model.Committee.Type)
</th>
<th>
@Html.DisplayNameFor(model => model.Role)
</th>
<th>
@Html.DisplayNameFor(model => model.EndDate)
</th>
<th>
@Html.DisplayNameFor(model => model.Source)
</th>
<th></th>
</tr>
@使用志愿者.BootstrapSupport
@模型IEnumerable
@使用(Html.BeginForm())
{
会员志愿服务名单
新活动
@DisplayNameFor(model=>model.Committee.Name)
@DisplayNameFor(model=>model.Committee.Type)
@DisplayNameFor(model=>model.Role)
@DisplayNameFor(model=>model.EndDate)
@DisplayNameFor(model=>model.Source)
除了显示属性外,还需要包括隐藏字段
@Html.HiddenFor(m => m.Role)
对未为其创建输入元素的每个属性执行此操作如果要将模型属性返回到索引,则必须将属性添加为管线值 返回重定向操作(“搜索”,新的{“键”,值})
隐藏字段是存储提交时要传递的数据的一种方法,使用路由更复杂,但更好的解决方案是作为角色url。对于一些隐藏的值可以很好地工作,但是如果您发现自己必须创建大量包含大量路由值的操作链接,请查看路由。您确定您在此处正确复制了视图吗?您的模型是一个IEnumerable,但没有迹象表明您在某个地方循环了它。您在此处提供的视图无效,即
model。
不会给出活动的任何属性作为它(model)是活动的集合
。我在这里没有看到保存值的输入元素,您只生成带有DisplayNameFor的标签。