Reputation: 510
I want to load the same view again by passing updated parameter from text input on the link click. I tried to use something like <a href="@Url.Action("Index", "Home", new {id = "txtCount".value }).
Not sure if there is even a way to do this. I know I could use partial but I want to reload the whole page with updated parameter. Thanks in advance for any help.
Controller
[HttpGet]
public ActionResult Index(int id)
{
return View(id);
}
View
@model int
@using (@Html.BeginForm())
{
<input id="txtCount" value="1" />
<a href="@Url.Action("Index", "Home", new { id = 5 @*// get value from txtCount*@ })">Update</a>
for (int i = 0; i < Model; i++)
{
<div>@i </div>
}
}
Upvotes: 1
Views: 1640
Reputation: 5286
Maybe something like this
<a href="#" id="mylink">Go!</a>
and binding with jquery
$("#mylink").click(function(){
document.location.href = '@Url.Content("~/Controller/Action")' + $("#mytxt").val();
return false;
});
Obviously with the proper validations if the textbox is empty and all that stuff.
You cannot add the id value to the @Url.Action
because it is processed before on the server side, before the page is rendered
Upvotes: 2