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

  • Home
  • SEARCH
  • 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 8266351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:07:46+00:00 2026-06-08T05:07:46+00:00

I am playing about with jQuery UI and PartialViews and have run into a

  • 0

I am playing about with jQuery UI and PartialViews and have run into a problem I can’t quiet get my head around.

This bit works as I expect:

<div>
    @Ajax.ActionLink("Test Me!", "dialogtest", new { id = Model.Id }, new AjaxOptions { InsertionMode = InsertionMode.Replace, UpdateTargetId = "dialogtest-view" })</td>
</div>
<div id="dialogtest-view">
</div>

this GETs to this action method

[HttpGet]
public PartialViewResult DialogTest(int id)
{
    //pretend to get something from DB here
    var vm = new DialogUITestVM();
    return PartialView("uidialog_partial", vm);
}

And returns me a PartialView which displays in the targeted div. jQuery + jQueryUI is used to pop this div up as a modal dialog. Part 1 of test done!

OK so now let’s say the PartialView returned is just a basic form with a textbox, something along the lines of:

@using (Html.BeginForm("DialogTest", "pages", FormMethod.Post))
{  
    @Html.HiddenFor(x => x.Id)
    @Html.TextBoxFor(x => x.Name)
    <button type="submit">Test Me!</button>
}

This is POSTd back to the controller fine –

[HttpPost]
public ActionResult DialogTest(DialogUITestVM vm)
{
    //arbitrary validation so I can test pass and fail)
    if (vm.Name.Equals("Rob"))
    {
        //error!
        vm.ErrorMessage = "There was an error you numpty. Sort it out.";
        return PartialView(vm);
    }

    //hooray it passed - go back to index
    return RedirectToAction("index");
}

However – if I make the action fail the validation, rather than targeting the PartialView to the div again, it redraws the whole page (which obviously loses the jQuery UI dialog).

What I want is: if validation fails, just update the div that contained the form.

Where am I going wrong?

  • 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-06-08T05:07:48+00:00Added an answer on June 8, 2026 at 5:07 am

    You could use an Ajax form in your partial instead of a normal form and use a OnSuccess callback in your AjaxOptions:

    @using (Ajax.BeginForm("DialogTest", "pages", new AjaxOptions { UpdateTargetId = "dialogtest-view", OnSuccess = "success" }))
    {  
        @Html.HiddenFor(x => x.Id)
        @Html.TextBoxFor(x => x.Name)
        <button type="submit">Test Me!</button>
    }
    

    and then modify your controller action respectively:

    [HttpPost]
    public ActionResult DialogTest(DialogUITestVM vm)
    {
        //arbitrary validation so I can test pass and fail)
        if (vm.Name.Equals("Rob"))
        {
            //error!
            vm.ErrorMessage = "There was an error you numpty. Sort it out.";
            return PartialView(vm);
        }
    
        //hooray it passed - go back to index
        return Json(new { redirectUrl = Url.Action("Index") });
    }
    

    and of course define the corresponding success callback in your javascript files:

    function success(result) {
        if (result.redirectUrl) {
            window.location.href = result.redirectUrl;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been playing about with canvas, but have stumbled across a problem. When
I have been playing around with Restkit for about a day now and its
I am playing about with the Zend Framework at the moment and I have
I've been playing about with Runnable s and have discovered that if you postDelayed
I am playing around with google app engine and I'm thinking about starting an
I've been playing around with C# console applications for about a year and I
This is going to seem a very strange question but im just playing about
I have been playing with Wordpress and jQuery - both new to me. The
I've been playing around with http://nixboxdesigns.com/projects/jquery-lavalamp/ for a navigation menu on a new site
I've been playing with jquery for a week or two now and have something

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.