Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6772403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:32:43+00:00 2026-05-26T15:32:43+00:00

I have a blog that has a sidebar with a partial view in it

  • 0

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.

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?

This is my view:

@using Blog.Models.Entities
@model Subscriber

<header>
    <h2>Subscribe</h2>
</header>

<p>Subscribe to my e-mail newsfeed.</p>

@using (Html.BeginForm("Form", "Subscription"))
{
    <div class="editor-label">@Html.LabelFor(subscriber => subscriber.Email)</div>
    <div class="editor-field ">@Html.EditorFor(subscriber => subscriber.Email)</div>

    @Html.ValidationMessageFor(subscriber => subscriber.Email)

    <input type="submit" value="Subscribe" />

    <p>@ViewBag.Result</p>
}

And the relevant pieces of controller that are processing the data:

public ActionResult Form()
{
    return PartialView("_Form");
}

[HttpPost]
public ActionResult Form(Subscriber subscriber)
{
    if (ModelState.IsValid)
    {
        Subscriber foundSubscriber = _repository.Subscribers.Where(s => 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);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:32:44+00:00Added an answer on May 26, 2026 at 3:32 pm

    I finally found the solution to the problem. I implemented it with AJAX and ended up with the following code:

    _Index.cshtml

    <header>
        <h2>Subscribe</h2>
    </header>
    
    <p>Subscribe to my e-mail newsfeed.</p>
    
    <div id="subscription-form">
        @{Html.RenderPartial("_Form");}
    </div>
    

    _Form.cshtml

    @using Blog.Models.Entities
    @model Subscriber
    @{
        AjaxOptions ajaxOptions = new AjaxOptions
        {
            LoadingElementId = "loading",
            LoadingElementDuration = 2000,
            HttpMethod = "Post",
            UpdateTargetId = "subscription-form"
        };
    }
    
    <div id="loading" style="display: none;">
        <p>Processing request...</p>
    </div>
    
    @using (Ajax.BeginForm("Index", "Subscription", ajaxOptions))
    {
        <div class="editor-label">@Html.LabelFor(subscriber => subscriber.Email)</div>
        <div class="editor-field ">@Html.EditorFor(subscriber => subscriber.Email)</div>
    
        @Html.ValidationMessageFor(subscriber => subscriber.Email)
    
        <input type="submit" value="Subscribe" />
    }
    

    _Succes.cshtml

    @using Blog.Models.Entities
    @model Subscriber
    
    <p id="subscription-result">@ViewBag.Result</p>
    

    And the following controller action methods:

    public ActionResult Index()
    {
        return PartialView("_Index");
    }
    
    [HttpPost]
    public PartialViewResult Index(Subscriber subscriber)
    {
        if (ModelState.IsValid)
        {
            Subscriber foundSubscriber = _repository.Subscribers.Where(s => 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("_Succes", subscriber);
        }
    
        ModelState.AddModelError("Email", "Please provide a valid e-mail address.");
        return PartialView("_Form", subscriber);
    }
    

    I hope this will help anyone trying to achieve the same in the future. BTW, I found the solution on this blog: http://xhalent.wordpress.com/2011/02/05/using-unobtrusive-ajax-forms-in-asp-net-mvc3/.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a blog that has a redirect loop, and I can't understand htaccess
I have a sidebar navigation that lists blog entry titles down the side of
I have this wordpress blog that has many pages with subpages that dropdown on
I have an app that has Basecamp-style subdomains, that is, I have Projects, Users,
Let's say I have a Blog posts table that has a rating field which
I have a websites that has a blog section, which pulls the data using
I have a blog section on my site that has the TinyMce editor. I
I have read in Ola Bini's blog that Ruby has influenced by CLU language,
In DotNetNuke, the blog posts have a control that has icons for facebook, google,
I have to setup a blog engine that has to be integrated with a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.