【问题标题】:How to pass values of partial view models on submit from another partial view如何在从另一个局部视图提交时传递局部视图模型的值
【发布时间】:2017-05-12 03:48:59
【问题描述】:

我有这个视图模型

    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>

当我在发布工具中点击提交时..它不会传递其他模型数据。 我是局部视图的新手。如果不是在局部视图中,我可以通过它们。但是为了获得正确和干净的外观,我想使用局部视图。

这是发帖工具部分

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

   }

但在提交时..除了 messagecontent 数据外,一切都是空的。 一直在寻找..辛苦..

【问题讨论】:

  • posting collections时你不能使用foreach
  • 我正在寻找的是如何保留现有/更新集合的价值,然后在我点击提交时发送它
  • 您必须遍历集合中的每个项目才能将其发布回服务器。每个项目都需要一个索引(请参阅链接的答案),以便您拥有@Html.TextBoxFor(m =&gt; Model.MailListData[i].UserEmail)

标签: c# razor model-view-controller partial-views


【解决方案1】:

您好,您的局部视图正在接受 RHAPostModel,但我在您的视图模型中看不到任何 RHAPostModel?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多