2016-12-27 34 views
0

我有这个视图模型如何通过对提交的局部视图模式的值从另一个局部视图

public class RHAPostModel 
    { 
     public PostingMain PostMainData { get; set; } 
     public List<MailingList> MailListData { get; set; } 
     public List<MailingGroup> MailGroupData { get; set; } 
    } 

这是我取得动作

public ActionResult Index() 
    { 
     var model = new RHAPostModel 
     { 

        MailListData = _dbrepo.GetDefaultRecipient().ToList(), 
        MailGroupData = _dbrepo.GetDefaultGroup().ToList() 

      }; 

     return View(model); 

    } 

这是我的看法

 @Html.Partial("_NavMenu",Model) 
<div class="col-md-3"> 
    @*side menu here*@ 
    @Html.Partial("_SideMenu",Model) 

</div> 


<div class="col-md-9" style="height:95%;"> 
    @*wysiwyg container here*@ 
    <div id="placeholder"> 
        <div id="Postcover" class="text-center"> 
         <center> 

          <div style="background-color:white;box-shadow: 10px 10px 5px #888888;width:75%;height:500px;padding:20px;border-radius:10px;"> 
           Complete Message Post Information 
          </div> 

         </center> 
        </div> 
        <div id="RushPostWrapper" > 

         @Html.Partial("_PostingTool",Model)  


        </div> 
     </div> 
</div> 

当我击中subm它在poststool里面,不会传递其他的modeldata。 我是新来的局部views..I能够通过他们,如果不是在部分views..but适当和清洁的外观,我想使用部分。

这是发布工具部分

 @model RHA.RushPost.ViewModel.RHAPostModel 



     @using (Html.BeginForm()) 
     { 
      @Html.AntiForgeryToken() 

     <div style="margin-bottom:30px;"> 
    <!-- This will contain your HtmlContent and use the TinyMCE editor--> 
      @Html.TextAreaFor(model => model.PostMainData.MessageContent, new { @id = "RushPostContent", @style = "margin:20px;" }) 

      @foreach (var x in Model.MailListData) 
     { 
      @x.userEmail <<-- i use this for testing and value is passed 
      } 
      @Html.HiddenFor(m => m.MailListData) 

     <div class="text-right" style="margin-top:20px;"> 
     <button type="button" class="btn btn-primary" id="btnImageUpdate">UpdateImage</button> 
     <button type="submit" class="btn btn-primary" id="btnSaveDraft" name="Command" value="Draft">Save as Draft</button> 
     <button type="submit" class="btn btn-info" id="btnSaveTemplate" name="Command" value="Template">Save as Template</button> 
     <button type="submit" class="btn btn-success" id="btnCampaign" name="Command" value="Send">Send Campaign</button> 
     <button name="ClientCancel" class="btn btn-danger" type="button" onclick="document.location.href=$('#cancelUrl').attr('href');">Clear</button> 
    </div> 
</div> 

    } 

但submit..everythin是除了在messageContent数据无效。 被searching..hard ..

+0

当[发布集合](http://stackoverflow.com/questions/19964553/mvc-form-not-able-to-post-list-of-objects)时,不能使用'foreach'。 – Jasen

+0

我在寻找的是如何保持现有/更新集合的价值,然后当我点击提交时也发送这个值 – CyberNinja

+0

您必须迭代集合中的每个项目才能将其发回服务器。每个项目都需要一个索引(请参阅链接的答案),以便您拥有'@ Html.TextBoxFor(m => Model.MailListData [i] .UserEmail)'。 – Jasen

回答

0

嗨,你的部分观点被接受RHAPostModel,但我看不到任何RHAPostModel您的视图模型里面?

相关问题