MVC3 Partial View - Can the DIV be inside the Ajax.BeginForm?
This is what i need to do:
I have a Partial View (PV):
@if (Convert.ToBoolean(ViewData["IsLogged"].ToString()))
{
<div id="onlineStatus">
ONLINE >>
@Html.ActionLink("Take a Break", "GoOffline", "Account")
</div>
}
else
{
<div id="offlineStatus">
IN A BREAK >>
@Html.ActionLink("Go Online", "GoOnline", "Account")
</div>
}
I put this PV on the *_layout.cshtml* so anytime i click on the ActionLink, the page should stay the same and the PV should only redraw itself in an asynchronous way.
I'm reading about using Ajax.BeginForm and it seems it needs a but my question is:
Q1: Shall I put the inside the Ajax.BeginForm ??@using (Ajax.BeginForm(new AjaxOptions {
UpdateTargetId="divStatus",
InsertionMode=InsertionMode.Replace })) {
<div id="divStatus">
@if (Convert.ToBoolean(ViewData["IsLogged"].ToString()))
{
<div id="onlineStatus">
ONLINE >>
@Html.ActionLink("Take a Break", "GoOffline", "Account")
</div>
}
else
{
<div id="offlineStatus">
IN A BREAK >>
@Html.ActionLink("Go Online", "GoOnline", "Account")
</div>
}
</div>
}
CONTROLLER ...to return itself?
public ActionResult GoOffline()
{
GoOffline();
ViewData["IsLogged"] = "False";
return PartialView("_OnlineStatusCtrl");
}
PROBLEM:
The entire page redraws as the PV so I guess it is NOT drawing itself inside theIs the problem how i call the Ajax.Beginform ?
Is the problem that I put the inside the Ajax.BeginForm ? 开发者_C百科Is the problem that I should put the Ajax.BeginForm on the _layout.cshtml instead?...is it's just that I simply still don't understand MVC ??
:--)
You dont need a Ajax form for this. You could wrap the PV in the div with the id divStatus and then use the following for the ActionLinks;
@Ajax.ActionLink("Take a break", "GoOffline", "Account", new AjaxOptions { UpdateTargetId = "divStatus", InsertionMode = InsertionMode.Replace })
Your controller would stay the same. This should work as expected
精彩评论