0

i have this viewmodel

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

This is my get action

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

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

            };

        return View(model);

    }

this is my view

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

When I hit submit inside the postingtool..it doesn't pass the other modeldata. I'm new to partial views..I was able to pass them if not in partial views..but for proper and cleaner look I wanted to use partial.

this is the posting tool part

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

   }

but on submit..everythin is null except for the messagecontent data. been searching..hard..

CyberNinja
  • 815
  • 9
  • 22
  • You can't use `foreach` when [posting collections](http://stackoverflow.com/questions/19964553/mvc-form-not-able-to-post-list-of-objects). – Jasen Dec 27 '16 at 21:27
  • what I'm looking for is how to keep the value of that existing/updated collection then send that too when I hit submit – CyberNinja Dec 28 '16 at 12:51
  • You'll have to iterate through each item in a collection to post it back to the server. Each item needs an index (see the linked answer) so that you have `@Html.TextBoxFor(m => Model.MailListData[i].UserEmail)`. – Jasen Dec 28 '16 at 18:03

1 Answers1

-1

Hi, your partial view is accepting RHAPostModel but I can't see any RHAPostModel inside your view model ?

Uwais
  • 17
  • 1
  • 5