查看到控制器通行證對象使用mvc4
@if (weekMaster != null)
{
using (Html.BeginForm("UpdatePlan", "generalPlan", FormMethod.Post, new { }))
{
<table class="table-bordered">
<tr>
@foreach (TermMaster obj in weekMaster.ToList())
{
<td align="center">
<span> @obj.termStartDate.ToString("dd MMM") - @obj.termEndDate.ToString("dd MMM")</span>
<br />
<input type="hidden" name="ObjHid" value="@obj" />
<input type="hidden" name="startDate" value="@obj.termStartDate" />
<input type="hidden" name="endDate" value="@obj.termEndDate" />
<input type="text" style="width:80%" name="weekSession" />
</td>
}
<td>
<input type="submit" value="Update" class="btn-primary" />
</td>
</tr>
</table>
} }
控制器
[HttpPost]
public ActionResult UpdatePlan(List<DateTime> startDate, List<DateTime> endDate, List<int> weekSession, List<TermMaster> ObjHid)
{
return View();
}
我使用輸入法<input type="hidden" name="ObjHid" value="@obj" />
但示出NULL
值嘗試上述TermMaster類Object合格合格Class Object from View to Controller
如果通過如單值startDate
和endDate
然後它工作正常。
我的代碼有什麼問題?如何在Post方法中傳遞類對象List?
建議你參考[這個答案](http://stackoverflow.com/questions/30094047/html-table-to-ado-net-datatable/30094943#30094943) –
但是什麼是降低性能你的應用程序通過嘗試發回一個'TermMaster'的集合,你甚至沒有編輯 –
@StephenMuecke在post方法我插入一些參數值與文本框的值,我需要從TermMaster的一些價值 – Pravin