1

I am developing MVC Web application. I use HttpPost via form.submit to request all views except first/default view. Therefore url in browser's address bar does not change i.e. stays http://mymachine:62846 When I try window.location.reload(true) url becomes http://mymachine:62846/Home/GetPartialView and web browser displays error:

Server Error in '/' Application. The resource cannot be found. Description: HTTP 404. Requested URL: /Home/GetPartialView

in HomeController Method GetPartialView is marked HttpPost:

[HttpPost]
public ActionResult GetPartialView(BroadcastedData data)

Based on aforementioned error my understanding is when window.location.reload(true) is executed browser sends HttpGet request or HttpPost w/o post data and server can't route request properly.

Am I wrong?

How can I reload page via code properly essentially mimicking user pressing CTRL + R? Thank you.

4

1 回答 1

0

由于您的操作方法属于类型[HttpPost],因此它需要发布数据。我希望有一种[HttpGet]操作方法可以通过它来呈现您的视图。您必须将特定操作方法([HttpGet])的 URL 设置为 window.location 而不是重新加载页面。

 window.location = url;

要在 ctrl+R 上执行此操作,请尝试以下代码:

$( document ).bind( 'keydown', function ( event )
                {
                    if ( event.which == 82 )//R=>82
                    {
                        if ( event.altKey )
                        {
                            window.location=desired_URL;
                        }
                    }
                } );
于 2013-04-24T11:22:10.880 回答