I have a Partial View in my main View listing a number of items.
Razor has correctly produced this partial view for me and has inserted action links (using the @Html.ActionLink command) pointing at an action at a controller and sending in the correct id.
All that works but I wish it to stay like that and not have to return anything!
Right now I am forced to send back something (Content, View, Redirect etc) which changes the main view and I don’t want that.
All I want to do is to take action on the server and leave it at that.
What else can I do?
Thanks
@model IEnumerable<PopupForm.Models.BOExplorerItem>
<h3>Explorer (partial)<br />
There are @Model.Count() explorer items.
</h3>
<ul class="ulexplorer">
@foreach (var item in Model)
{
<li>
<div class="boitem">
<h5>@item.FullName [<i> @item.Code </i>]</h5>
<span>Level: @item.Level</span>
@Html.ActionLink("Select", "SelectEntity", "Explorer", new { code = @item.Code }, null)
</div>
</li>
}
</ul>
What you can do is listen to the click event of link and make an ajax call instead of the normal redirect behaviour. Let the ajax call intitate what code you want to execute.
So change your link like this to apply a css class to our links so that we can use it as our jQuery element selector.
Now some javascript to bypass the click event
If you want your Action method to execute normal (return View /Other content) on normal non-ajaxified request, you may add an if condition checking to see whether the request is ajax or not