Reputation: 529
I'm trying to redirect in same Index page that do multiple actions.
The problem is when in Index page with id parameter "http://example.com/Student/Index/1" Url.Action("Index") or Html.ActionLink("Index") will always generate : "http://example.com/Student/Index/1" instead of "http://example.com/Student"
This happen on Menu and Breadcrumb.
Controller :
public ActionResult Index(int? id)
{
if (id == null) {
// Show List
} else if (id <= 0) {
// Show Create Form
} else {
//Show Edit Form
}
}
Is there any way to redirect to same page without parameter on View?
Upvotes: 2
Views: 3278
Reputation: 10319
There can be multiple ways. Action Link which generates the html link
@Html.ActionLink("link text", "someaction", "somecontroller", new { id = "123" }, null)
generate as :
<a href="/somecontroller/someaction/123">link text</a>
URL.action which only genrates url which you will need to put in html link tag
Url.Action("someaction", "somecontroller", new { id = "123" })
generates
/somecontroller/someaction/123
Upvotes: -2
Reputation:
You can set the route value to an empty string
@Html.ActionLink("Link text", "Index", new { id = "" })
Upvotes: 5