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 3434208
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:40:12+00:00 2026-05-18T07:40:12+00:00

I’m currently using ASP.NET MVC3 RC and I’m using the unobtrusive JQuery validations as

  • 0

I’m currently using ASP.NET MVC3 RC and I’m using the unobtrusive JQuery validations as described by Brad Wilson on his blog. It works great but when I send my form (in Ajax) to the server, I do some server side validations and return the same row (that is included in a partial view) if my model state isn’t valid. 2 problems with that :

1st : When I do a return PartialView in my action, all the unobtrusive attributes aren’t rendered. I found a “non elegant” way to do it but when I do it, client validations are broken. After I return from my action, even if I call jQuery.validator.unobtrusive.parse() on my updated row, $("form").valid() always return true even if it’s not the case.

2nd : I want my rendered view to be render as a string on the server so I can send it back in a JsonResult (ex:myJSonResult.html=RenderPartialToString("partialName",model)).

Has a reference, there’s my view (editInvitation) :

<td>
    <%= Html.HiddenFor(x=>x.ID,new{id="ID"}) %>
    <%= Html.HiddenFor(x=>x.GroupID,new{id="GroupID"})  %>
    <%: Html.TextBoxFor(x => x.Name, new { id = "Name" })%><%:Html.ValidationMessageFor(x=>x.Name) %>
</td>
<td>
    <%: Html.TextBoxFor(x => x.Email, new { id = "Email" })%>  <%:Html.ValidationMessageFor(x=>x.Email) %>
</td>
<td>
    <%: Model.Status.ToFriendlyName()%>
</td>
<td>
  <%= InvitationsViewModel.RenderActions(Model, Html, InvitationsViewModel.CreateRowID(Model.ID))%>
</td>

And my controller action :

if (TryUpdateModel(invitation))
{
    validModel = true;
    //Other stuff
}
if (Request.IsAjaxRequest())
{
     //TODO : I return a partial view but I would prefer to return a JSonResult with the rendered view as a string in an Property of my JSon result
     return PartialView(validModel ? "DisplayInvitation" : "EditInvitation", invitation);
}

Thanks

  • 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-18T07:40:13+00:00Added an answer on May 18, 2026 at 7:40 am

    I finally make it worked. This is how :

    HtmlHelper helper = GetHelper();
    MvcHtmlString partialView = helper.Partial("myView" , model);
    var result = new { success = ModelState.IsValid, html = partialView.ToString() };
    return Json(result);
    

    There’s the helper functions:

    protected HtmlHelper GetHelper()
    {
        return GetHelper(string.Empty);
    }
    protected HtmlHelper GetHelper(string formID)
    {
        HtmlHelper helper = new HtmlHelper(getViewContext(formID), new ViewPage { ViewData = this.ViewData });
        helper.EnableClientValidation(isClientValidationEnabled());
        helper.EnableUnobtrusiveJavaScript(isUnobtrusiveJavascriptEnabled());
        return helper;
    }
    private ViewContext getViewContext(string formID)
    {
        var vc = new ViewContext(this.ControllerContext, new WebFormView(this.ControllerContext, "~/Views/Home/Index.aspx"), this.ViewData, new TempDataDictionary(), new System.IO.StringWriter());
        vc.UnobtrusiveJavaScriptEnabled = isUnobtrusiveJavascriptEnabled();
        vc.ClientValidationEnabled = isClientValidationEnabled();
        vc.FormContext = new FormContext { FormId = formID };
        return vc;
    }
    

    I’m not sure it’s the best way to do it but it worked for me. Let’s hope the ASP.NET MVC team would provide an easier way to render a view as a string.

    Thanks

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

Sidebar

Related Questions

I want use html5's new tag to play a wav file (currently only supported
I am currently running into a problem where an element is coming back from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm making a simple page using Google Maps API 3. My first. One marker
I have a JSP page retrieving data and when single or double quotes are
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string

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.