English 中文(简体)
MVC3 动态回归
原标题:MVC3 Dynamic Return URL

我想有一种观点,即与用户从这一角度浏览的哪一页的长度挂钩。

Let s say I have a View and relative Action named InfoPage, and on this page I want a link that simply says Return .

如果用户在AlpA和Navigates到InfoPage上,就把“回归”连接到A页。

如果用户在网页B上,并向InfoPage报到,则点击“回归”链把用户归到网页B。

我认为,这样做最容易的手段是,将回归城市作为InfoPage所用模式的财产。

我的问题是,我是如何获得这种回报的。

    public ViewResult InfoPage(){
       var model = new InfoPageModel(); 
       //Set my model s other properties here...
       model.ReturnUrl =   //Where do I get this?
       return view(model);
    }

And then in my view

    <a href="@Model.ReturnUrl">Return</a>
最佳回答

这样做的最有力方式是从电线上将直线参数传入你网页。 该网页必须连接起来,才能通过自己的URL。 (> 查询。 乌尔尔·>。

You could also use Request.UrlReferrer in your control, but not all browsers send Referer headers.

问题回答

积极建设回返 3. 在任何控制人员的行动范围内:

var formCollection =
    new FormCollection
        {
            new FormCollection(this.HttpContext.Request.Form),
            new FormCollection(this.HttpContext.Request.QueryString)
        };

var parameters = new RouteValueDictionary();

formCollection.AllKeys
    .Select(k => new KeyValuePair<string, string>(k, formCollection[k])).ToList()
    .ForEach(p => parameters.Add(p.Key, p.Value));

var returnUrl =
    this.Url.Action(
        this.RouteData.Values["action"].ToString(),
        this.RouteData.Values["controller"].ToString(),
        parameters
    );

相关:。 NET MVC? (同,但从任何观点来看)





相关问题
Using jquery to get a partial view and updating the UI

I need to render a partial view (returned from the controller) to show some customer summary details. This will need to happen when the user clicks on a button. In the the mean time the user can ...

MVC 2 / MVC 3 / MVC 4

MVC 2 我们可以轻松地创造领域。 现在,我的问题涉及nes地区(地区内)。

Asp.Net MVC 2 - Changing the PropertyValueRequired string

Using a resx file in the App_GlobalResources directory, I ve been able to change the default message for the PropertyValueInvalid string of the model validators. But it doesn t work to translate the ...

ASP.NET MVC 3 - What features do you want to see? [closed]

I know a bunch of people that are really enjoying the improvements that ASP.NET MVC 2 made over the first release. I have just started to migrate our MVC 1 project over and so far areas has totally ...

热门标签