开发者

asp mvc3 : load page to certain element id

开发者 https://www.devze.com 2023-03-26 01:24 出处:网络
I am building a mobile site with asp.net mvc3 and just getting to know the mvc framework. I have a requirement that I can\'t use javascript since some phones are not compatible. I have a form that is

I am building a mobile site with asp.net mvc3 and just getting to know the mvc framework. I have a requirement that I can't use javascript since some phones are not compatible. I have a form that is being validated on the postback. If validation is invalid I would like to reload the page to the form instead of the top of the page. Is it possible to have my controller tell the view to load to the form id instead of just saying return View("ViewName开发者_如何学JAVA");?

Thanks for your help, B


Without javascript your best bet is to use anchors:

<a name="foo"></a>
<form action="@Url.Action(null)#foo" method="post">
    ...
    <input type="submit" value="OK" />
</form>

When you submit the form it will post to the following url /Home/Index#foo which should scroll the browser automatically to the corresponding anchor with this name which is just at the top of the form.


See this nice solution (there are a lot more but that one is very efficient and small): How do I maintain scroll position in MVC?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号