In MVC .NET application we can easily use PartialView to print the output of an ASCX file.
For example, I have Book.ascx file, I could have this in the controller
public ActionResult Book(int id)
{
BookModel model = new BookModel() { bookId = id };
return PartialView("Book", model);
}
which returns the output of Book.ascx
Is there any way we can do this in a normal .NET website?
I want to be able to use it with AJAX, eg.
When an Update button is clicked, replace the content of <div id="book123"> with the output of /Book.ascx?id=123
Is that possible?
I am looking for something like this
$.get('Book.ascx?id=123', function(data) {
$("#book123").html(data);
});
But that won’t work because you can’t call Book.ascx directly…
Thanks in advance
well, it is doable, but not pretty 🙂
you could instantiate your control, and instead of passing the key via QueryString, do it via exposed property:
than you could render the HTML out of it with something like
than you would pass that html back via your service and insert into the div etc..