jquery - MVC 4 - How can I load a View using JavaScript -


i pretty new mvc , javascript. have dropdown ('processgrouprevisions') on view , when user selects item in drop down, want execute action in controller render new view. have following code sort of stubbed out. know it's not right (because doesn't work), i'm not sure need make work.

        // handles onchange revisions dropdown.         $("#processgrouprevisions").change(function () {             if ($("#processgrouprevisions").prop("value") == "-1") {                 '@url.action("addnewrevision", "setpointmanagement", new routevaluedictionary { { "processgroupid", viewbag.processgroupid } })';             }         }); 

you can try use jquery load method:

$('#yourcontainer').load('/controllername/actionname'); 

"yourcontainer" must in case id of html element want use container view. may want have logic avoid having hard-coded url controller there. in case can this:

var baseurl = '@url.content("~")'  $("#yourcontainer").load(baseurl + "controllername/actionname"); 

note baseurl variable must defined in cshtml file , not in separate js file, because must handled on server-side.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -