Reputation: 456
In short, I'm trying to hit an anchor on the page I am submitting to.
So my code looks like:
@using (Html.BeginForm("Times#" + Model.SelectedTimeSort, "Patron", FormMethod.Post, new { id = "frmBuildings" }))
but on the form it comes out as:
<form action="/Times%23Evening" id="frmBuildings" method="post">
How do I set this up to submit and pass an anchor tag?
Upvotes: 1
Views: 2761
Reputation: 3952
Just get rid of the Html.BeginForm and use an html form tag with a Url.Action
<form action="@Url.Action("Times", "Patron")#@Model.SelectedTimeSort" id="frmBuildings" method="post">
</form>
Relying on javascript per the correct answer seems like overkill just to keep the "BeginForm" around.
Upvotes: 1
Reputation: 514
Assuming you are posting to another MVC method on your application:
You would need to add some JavaScript to the page, then in your ViewModel add an Anchor string property which is set in the MVC controller postback code, when the view loads the javascript (onLoad) can detect the parameter and scroll the page to the anchor:
location.hash = "#" + "@(Model.MyAnchorName)";
Upvotes: 2