1

I have table on my view page. One of the cells has an ID (say "x"). When a certain button is clicked a JS function is called, and the purpose is to dynamically change the partial view contained inside that cell using the code:

$("#X")[0].innerHTML = @Html.Partial("PartialViewName");

It works perfectly on firefox, but not in IE8. Also, FIY,the partial view is an AJAX form.

1
  • trying using quotes for setting the innerHTML value like this : $("#X")[0].innerHTML = "@Html.Partial("PartialViewName")"; Commented Jan 5, 2012 at 8:01

1 Answer 1

1

You can load the partial view by ajax like this using Jquery load,

$("#X").load(@Url.Action("action","controller"));

and in the controller you have to return the partial view like this,

public ActionResult Action(){  
    return PartialView('PartialViewName')
}
Sign up to request clarification or add additional context in comments.

2 Comments

It works very well, although I'd still like to know what is the "best practice" way to do that using MVC without using jquery load(). Thanks!
If you want to load it dynamically via ajax you can use JQuery get, post , load methods as you want. And if you do not want to load it like that (if it is not heavy to load at the initial page load ) you can just hide that content when page loads. And then oyu can show it when user clicks the button.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.