Note that there are some explanatory texts on larger screens.

plurals
  1. POReturning data to a partial view
    primarykey
    data
    text
    <p>I have a blog that has a sidebar with a partial view in it that enables users to sign up for my e-mail newsfeed. What I'm trying to do is returning the user to the page they came from after posting some data, and displaying any validation or return messages in the form's partial view.</p> <p>The problem is that my partial view opens in a new window (without the lay-out). How can I fix this so it returns to my blog, with the return data in de sidebar?</p> <p>This is my view:</p> <pre><code>@using Blog.Models.Entities @model Subscriber &lt;header&gt; &lt;h2&gt;Subscribe&lt;/h2&gt; &lt;/header&gt; &lt;p&gt;Subscribe to my e-mail newsfeed.&lt;/p&gt; @using (Html.BeginForm("Form", "Subscription")) { &lt;div class="editor-label"&gt;@Html.LabelFor(subscriber =&gt; subscriber.Email)&lt;/div&gt; &lt;div class="editor-field "&gt;@Html.EditorFor(subscriber =&gt; subscriber.Email)&lt;/div&gt; @Html.ValidationMessageFor(subscriber =&gt; subscriber.Email) &lt;input type="submit" value="Subscribe" /&gt; &lt;p&gt;@ViewBag.Result&lt;/p&gt; } </code></pre> <p>And the relevant pieces of controller that are processing the data:</p> <pre><code>public ActionResult Form() { return PartialView("_Form"); } [HttpPost] public ActionResult Form(Subscriber subscriber) { if (ModelState.IsValid) { Subscriber foundSubscriber = _repository.Subscribers.Where(s =&gt; s.Email.Equals(subscriber.Email)).FirstOrDefault(); if (foundSubscriber != null) { ModelState.AddModelError("Email", "This e-mail address has already been added."); return PartialView("_Form", subscriber); } _repository.SaveSubscriber(subscriber); ViewBag.Result = "Succesfully subscribed to the newsletter."; return PartialView("_Form"); } ModelState.AddModelError("Email", "Please provide a valid e-mail address."); return PartialView("_Form", subscriber); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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