Redirect to the Home Index action.
If you are within the Home Controller do this:
public ActionResult Index()
{
return View()
}
[Route("user/{userId}")]
public async Task<ActionResult> GetUser(int userId)
{
var vm = await _userService.GetVm();
return PartialView("_JSRedirect", new JSRedirectViewModel() { Location = Url.Action("Index") });
}
Your JSRedirectViewModel will look like this:
public class JSRedirectViewModel
{
public string Location { get; set; }
}
Your _JSRedirect Partial View will look like this:
@model Adservio.Models.JSRedirectViewModel
@{
Layout = null;
}
<script type="text/javascript">
window.location = '@Model.Location';
</script>
You would typically call the GetUser Action from your view this way:
<div id="AlertDiv"></div>
<div id="MsgDiv"></div>
<button onclick="GetUser()">Perform User Action</button>
<script type="text/javascript">
$.post({
url: "@Url.Action("GetUser")",
data: { },
global: false,
success: function (r) {
$('#AlertDiv').html(r);
}
});
</script>
Apologies for the JQuery...