asp.net mvc - MVC 4 - Ajax - Replace one partial one view with another -
i'm trying replace contents of div in main view partial views depending on @ajax.actionlink clicked.
initally load _caseload partial view able switch between 2 partial views _caseload , _vacancies when click on relevant actionlink. have bothe partial views , index view in 'main' folder.
when click on 'vacancies' link briefly shows loadingelementid not replace _caseload partial view _vacancies partial view?
controller action (maincontroller):
public actionresult index(int page = 1, string searchterm = null) { mainindexviewmodel model = new mainindexviewmodel() // populate model return view(model); }
main index view:
@model project.webui.models.mainindexviewmodel @{ viewbag.title = "index"; layout = "~/views/shared/_layout.cshtml"; } <div id="mainindex"> <div id="menu"> @ajax.actionlink("caseload", "_caseload", "main", null, new ajaxoptions() { updatetargetid = "main", insertionmode = insertionmode.replace, httpmethod = "get", loadingelementid = "busycycle" }) | @ajax.actionlink("vacancies", "_vacancies", "main", null, new ajaxoptions() { updatetargetid = "main", insertionmode = insertionmode.replace, httpmethod = "get", loadingelementid = "busycycle" }) </div><hr/> <div id="busycycle" style="display:none;"><img src="~/content/images/preloader-w8-cycle-black.gif" /></div> <div id="main"> @html.partial("_caseload") </div> </div>
your call @ajax.actionlink wrong, doing this:
@ajax.actionlink("caseload", "_caseload", "main", null, new ajaxoptions() { updatetargetid = "main", insertionmode = insertionmode.replace, httpmethod = "get", loadingelementid = "busycycle" })
which means link text "caseload", , action called in "maincontroller" "_caseload"? isn't "_caseload" name of partial view?
to fix this, must create caseload , vacancies actions in maincontroller, make both methods return partialview("_caseload.cshtml", model); or partialview("_vacancies.cshtml, model) below:
public actionresult caseload(int page = 1, string searchterm = null) { mainindexviewmodel model = new mainindexviewmodel() // poopulate model return partialview("_caseload.cshtml", model); }
i cut off implementation details idea how fix issue.
Comments
Post a Comment