2013-03-22 17 views
0

我試圖在表單提交時將整個模型數據返回給索引文章。它只返回通過URL參數傳遞的ID。爲什麼?索引帖子不能將整個模型返回給控制器?

enter image description here

@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> 
+1

你確定你在這裏正確地複製了你的視圖嗎?你的模型是一個IEnumerable,但沒有跡象表明你在某處循環。您在這裏展示的視圖是無效的,即'model.'不會給出'Activity'的任何屬性,因爲它(模型)是Activity的集合。 – 2013-03-22 13:53:02

+1

我沒有看到輸入元素可以在這裏保存你的值,你只是用DisplayNameFor生成標籤。 – tpeczek 2013-03-22 14:12:04

回答

0

除了顯示對屬性,你需要包括隱藏字段爲好。

@Html.HiddenFor(m => m.Role) 

這樣做對你如果你想在模特屬性返回到你的屬性,路由值添加索引沒有爲

0

創建input元素的屬性。

return RedirectToAction(「Search」,new {「key」,value});

隱藏字段是存儲數據以通過提交進行傳遞的一種方式,使用路由作爲角色url更復雜但更好。對於一對隱藏的值可以正常工作,但如果您發現自己必須創建大量的具有大量路由值的操作鏈接,請查看路由。

相關問題