I have a Partial View with two opposite ActionLinks inside:
<div id="divStatus>
@if (IsAuthenticated)
Html.ActionLink("Say Bye", "ProcBye", "Account")
else
Html.ActionLink("Say Hi", "ProcHi", "Account")
</div>
Each Action link calls a different method on the Controller.
I hear I should use Ajax.BeginForm but I’m still NOT clear how to put this?
My understanding is that I need a <div id="divStatus"> to display the result, but in my case …the result is the Partial View itself.
QUESTION: How do I ensure make it so the Controller just refreshes the calling Partial View??
Shall I just add a div outside the PV?
Shall I add the div inside the PV surrounding the ‘@if (IsAuthenticate)’ call?
Is it better to use Ajax.BeginForm or Ajax.ActionLink in this case?
CODE: What should the code for the Controller look like?
public ActionResult ProcBye()
{
// do something on the server
// set IsAuthenticated = false;
return PartialView("_myPV");
}
There is NO Validation Involved, NO “external” div that needs to be populated, just a simple refresh of the PV independently from what page the PV is located.
Any help will be truly appreciated !!!
Personally I wouldn’t use neither. I would use a separate javascript file in which I would AJAXify the link:
where resultdiv will be a div which will be update with the partial result returned from the controller action:
You just need to put the
mylinkclass:You could also use
Ajax.ActionLinkif you wanted to:Just don’t forget to include the jquery unobtrusive ajax script in this case: