I have a simple code from controller
public ActionResult CreatePage() {
return PartialView( "APage" );
}
and the part of that page APage is:
<table class="@className">
<tr>
...
</tr>
</table>
In javascript, I want to generate APage with different class name (css class name)
$.post('CreatePage', function(data) {
$('.result').html(data);
});
How to pass in controller function (if I would declare : public ActionResult CreatePage(string cssClass) { ... }) the parameter to PartialView function ?
Means
I want like:
public ActionResult CreatePage( string cssClass ) {
return PartialView( "APage", cssClass );
}
And I want to use that css class into APage view.
For example:
-
If I call
$.post('CreatePage', {cssClass: 'aClass' ,function(data) {
$('.result').html(data);
}); -
Then it will call
public ActionResult CreatePage( string cssClass ) { return PartialView( "APage", cssClass ); //cssClass = 'aClass' } -
And return the view like
<table class="aClass">
<tr>
...
</tr>
</table>
Thank you
I’m not sure if I understood you correctly, but your example, I think, is already on the right track.
In your partial view, add this at the very top:
And then in your partial view, change the table tag definition to