I have a search text input in my layout page in a partialView and other 3 pages that uses layout:
@using (Html.BeginForm("Search", "Product"))
{
@Html.TextBoxFor(m => m.SearchText)
@Html.ValidationMessageFor(m => m.SearchText)
<input type="submit" value="Search"/>
}
When it goes inside Product/Search action, how can I know where it came from and return to the correct page with a message assuming the 3 other pages uses different ViewModels?
In your layout, modify your
BeginFormto include the request path in the route values:Then, in your controller, you can finish up by redirecting to that path:
And that should do the trick. If you need to pass additional information along, you can just append a query string to the path: