asp.net mvc - How can i load Partial view inside the view -
i confuse partial view...
i want load partial view inside main view ...
here simple exmaple...
i loading index.cshtml of homecontroller index action main page..
in index.cshtml creating link via
@html.actionlink("load partial view","load","home")
in homecontroller adding new action called
public partialviewresult load() { return partialview("_loadview"); }
in _loadview.cshmtl having
<div> welcome !! </div>
but, when run project, index.cshtml renders first , shows me link "load partial view" ... when click on goes new page instade of rendering welcome message _loadview.cshtml index.cshtml.
what can wrong?
note: don't want load page through ajax or don't want use ajax.actionlink
if want load partial view directly inside main view use html.action
helper:
@html.action("load", "home")
or if don't want go through load action use htmlpartial hepler:
@html.partial("_loadview")
if want use ajax.actionlink
, replace html.actionlink
with:
@ajax.actionlink( "load partial view", "load", "home", new ajaxoptions { updatetargetid = "result" } )
and of course need include holder in page partial displayed:
<div id="result"></div>
also don't forget include:
<script src="@url.content("~/scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script>
in main view in order enable ajax.*
helpers. , make sure unobtrusive javascript enabled in web.config (it should default):
<add key="unobtrusivejavascriptenabled" value="true" />
Comments
Post a Comment