Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get partialview data in this situation?
    text
    copied!<p>in my MVC 4 web apps, I have a model data with a jQuery tab table, in each tab, I have some embedded tables which works as one to many relationship with this main tab table, in main tab table, I have a button ("Add"), when click it, a row of data field beside it with the data user entered will be added to the children table (which is a partialview) embedded in one of tab table, now, the code behind the button and controller saved the data to table, but the current embedded does not updated to show the new added table data at all. I appreciate anybody can help me out this problem. This is the javascript behind Add button, </p> <pre><code> function AddMeal() { //Build your Product var product = { "MDate": $("#MDate").val(), "MRegion": $("#MRegion").va(), "MBAmount": $("#MBAmount").val(), "MLAmount": $("#MLAmount").val(), "MDAmount": $("#MDAmount").val(), "FINtravelID": $("#FINtravelID").val() }; $.post('@Url.Action("Edit1","Travel")', product, function (data) { if (data == null) { location = location.href; } else { //Populate your MealTable element with the results of your Partial View $('#MealTable').html(data); } });} </code></pre> <p>This is controller:</p> <pre><code> [HttpPost] public ActionResult Edit1( Meal product) { db.Meals.Add(product); db.SaveChanges(); ViewBag.SaveMeal = "1"; return PartialView("_MealPartial", product); } </code></pre> <p>this is the razor view related to this question,</p> <pre><code> @model Travelmvc.Models.FINtravel &lt;input type="button" value="Add" id="AddButton1" onclick="AddMeal()"/&gt; &lt;div id="MealPartial"&gt; @Html.Partial("~/Views/Shared/_MealPartial.cshtml") &lt;/div&gt; </code></pre> <p>This is partialview details codes:</p> <pre><code> @model Travelmvc.Models.FINtravel &lt;table class="MealT" id="MealTable" &gt; @if (Model != null) { if (Model.Meals != null){ //here this line code always returns null, that is why the read data created in SQL table can not display in the loop foreach (var item in Model.Meals) { &lt;tr&gt; &lt;td&gt; @Html.DisplayFor(modelItem =&gt; item.MDate) &lt;/td&gt; &lt;td&gt; @Html.DisplayFor(modelItem =&gt; item.MRegion) &lt;/td&gt; &lt;td&gt; @Html.DisplayFor(modelItem =&gt; item.MBAmount) &lt;/td&gt; &lt;td&gt; @Html.DisplayFor(modelItem =&gt; item.MLAmount) &lt;/td&gt; &lt;td&gt; @Html.DisplayFor(modelItem =&gt; item.MDAmount) &lt;/td&gt; &lt;td&gt; @Html.DisplayFor(modelItem =&gt; item.MTAmount) &lt;/td&gt; &lt;td&gt; @Html.DisplayFor(modelItem =&gt; item.MProduct) &lt;/td&gt; &lt;td&gt; @Html.DisplayFor(modelItem =&gt; item.MRC) &lt;/td&gt; &lt;td&gt; @Html.DisplayFor(modelItem =&gt; item.MLocation) &lt;/td&gt; &lt;td&gt; @Html.DisplayFor(modelItem =&gt; item.MPOC) &lt;/td&gt; &lt;td&gt; aa &lt;/td&gt; &lt;td&gt; ff &lt;/td&gt; &lt;/tr&gt; } ... </code></pre> <p>and this is the model of FINtravel and Meal.</p> <pre><code>public class FINtravel { public int FINtravelID { get; set; } public string ClaimNo { get; set; } public virtual ICollection&lt;Meal&gt; Meals { get; set; } } public class Meal { public int MealID { get; set; } public int FINtravelID { get; set; } public virtual FINtravel FINtravel { get; set; } } </code></pre> <p>So my question is why the meal data created in Edit1 controller not display in razor view (partialview)? But I can see the data was saved in SQL table from back end. can anybody help me out of this problem? thank a lot in advance.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload