Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to put multiple partials in one page? MVC4
    text
    copied!<p>I'm only starting in MVC4 and I'm trying to put multiple partial views in one page every partial is suppose to be with different data but it is always show one partial with only one data every partial is shown on button click.</p> <p>This is the view code:</p> <pre><code> &lt;section id="comments"&gt; &lt;h3&gt;Comments&lt;/h3&gt; @{ foreach (MvcApplication4.Models.comment item in postComments) { &lt;article&gt; &lt;p&gt;@item.body&lt;/p&gt; using (Html.BeginForm("Delete", null, new { id = item.ID ,pid = item.idPost}, FormMethod.Post)) { @Html.HttpMethodOverride(HttpVerbs.Delete) &lt;button type="submit" class="button delete" &gt;Delete&lt;/button&gt; } &lt;section&gt; &lt;button type="submit" class="button Edit" id="edit" onclick="return showHide();" &gt;Edit&lt;/button&gt; &lt;div id="partial" hidden="hidden"&gt; @Html.Partial("editCom",item) &lt;/div&gt; &lt;/section&gt; } } &lt;/article&gt; } } &lt;/section&gt; </code></pre> <p>This is the showhide partial: </p> <pre><code> &lt;script type="text/javascript" language="javascript"&gt;// &lt;![CDATA[ function showHide() { var ele = document.getElementById("partial"); if(ele.style.display == "block") { ele.style.display = "none"; } else { ele.style.display = "block"; } } // ]]&gt;&lt;/script&gt; </code></pre> <p>This is the partial : </p> <pre><code>@using MvcApplication4.Models @model MvcApplication4.Models.comment @{comment com = Model; } @using (Html.BeginForm("Edit", null,new{ pid=com.idPost,cid=com.ID}, FormMethod.Post)) { &lt;fieldset&gt; &lt;div class="editor-label"&gt; @Html.LabelFor(x =&gt; com.user) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.LabelFor(x =&gt; com.user,Session["username"].ToString()) @Html.ValidationMessageFor(x =&gt; com.user) &lt;/div&gt; &lt;div class="editor-label"&gt; @Html.LabelFor(x =&gt; com.email) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.EditorFor(x =&gt; com.email,com.email) @Html.ValidationMessageFor(x =&gt; com.email) &lt;/div&gt; &lt;div class="editor-label"&gt; @Html.LabelFor(x =&gt; com.url) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.EditorFor(x =&gt; com.url,com.url) @Html.ValidationMessageFor(x =&gt; com.url) &lt;/div&gt; &lt;div class="editor-label"&gt; @Html.LabelFor(x =&gt; com.body) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.EditorFor(x =&gt; com.body,com.body) @Html.ValidationMessageFor(x =&gt; com.body) &lt;/div&gt; &lt;p&gt; &lt;input type="submit" value="save" /&gt; &lt;/p&gt; &lt;/fieldset&gt; } </code></pre>
 

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