开发者

Storing ActionLink in model or RouteValueDictionary in model

开发者 https://www.devze.com 2023-03-22 07:16 出处:网络
I wish to store an action link in the model. Something like public MvcHtmlString ActionLink_New { get { return Html.ActionLink(\"new\", \"Edit\", \"News\", new { Area = \"Admin\" }, null); }

I wish to store an action link in the model.

Something like

public MvcHtmlString ActionLink_New
{
    get { return Html.ActionLink("new", "Edit", "News", new { Area = "Admin" }, null); }
}

It appears the model needs a webviewpage context.

Failing that, I thought I would store just the route values.

public RouteValueDictionary[] RouteValue_New 
{
    get { return new RouteValueDictionary[] { Area = "Admin" };开发者_如何学编程 }
}

//View
@Html.ActionLink("new", "Edit", "News", Model.RouteValue_New, null)

The Area in the property is red. Is either or both scenario achievable. What do i need to add to get this to work, thanks.


try this

public object RouteValue_New
    {
        get { 
            return new { Area = "Admin" }; 
        }
    }
0

精彩评论

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