T4MVC @ Url.Action(MVC.Controller.Action())呈现"面积="参数查询字符串 [英] T4MVC @Url.Action(MVC.Controller.Action()) Renders "?Area=" Parameter in QueryString

查看:199
本文介绍了T4MVC @ Url.Action(MVC.Controller.Action())呈现"面积="参数查询字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我渲染菜单从局部的行动直接向布局,使用:

I am rendering a menu from a Partial Action directly to the layout, using:

@Html.Action(MVC.Menu.Index())

这个动作,决定了渲染的菜单部分。例如,一个公共菜单部分。这些谐音之内,我也使用T4MVC渲染链接:

This action, determines which Menu partial to render. For instance, a public menu partial. Within these partials, I am also using T4MVC to render the links:

<ul id="navHolder">
<li class="level1">
    <ul class="mainMenu">
        <li><b>@Html.ActionLink("Welcome", MVC.Home.Index())</b>
           ... 

由于某些原因,由T4MVC呈现的网址包含面积=?的结尾:

For some reason, the Urls rendered by T4MVC include "?Area=" at the end:

 <ul id="navHolder">
    <li class="level1">
        <ul class="mainMenu">
            <li><b><a href="/home/index?Area=">Welcome</a></b>
               ...

我在我的项目中没有的地区,我已经变成了IncludeAreasToken设置为false。奇怪的是,如果我使这只是发生局部使用@ Html.Action - 如果我把它作为@ Html.Partial参数未提供,而该链接是干净的,正确的。 (我不希望以使其作为一个部分了,所以请不要提供,作为一个建议;)

I have NO areas in my project and I have turned the "IncludeAreasToken" setting to false. Oddly, this only happens if I render the partial using "@Html.Action" -- if I pull it in as "@Html.Partial" the parameter isn't rendered and the link is clean and correct. (I don't want to render it as a partial though, so please don't offer that as a suggestion ;)

任何人在那里碰上这之前?

Anyone out there run into this before?

推荐答案

奇怪的事情是怎么回事就在这里,我不知道是否有在根某种MVC的bug。即使不使用T4MVC,出现这种情况,如果你写的:

Something strange is going on here, and I wonder if there is some kind of MVC bug at the root. Even without using T4MVC, this happens if you write:

@Html.ActionLink("Welcome", "Index", "Home", new { Area = "" }, null)

在常规的视图,这并不产生伪造?面积=,而在一个Html.Action调用它。我要问的球队的人。

In a regular view, this doesn't generate the bogus ?Area=, while in a Html.Action call it does. I need to ask someone on the team.

现在,你可以通过删除这一行变通办法(约310行)的t4mvc.tt:

For now, you can workaround by deleting this line (around line 310) in t4mvc.tt:

<# if (MvcVersion >= 2) { #>result.RouteValueDictionary.Add("Area", area ?? "");<# } #> 

这篇关于T4MVC @ Url.Action(MVC.Controller.Action())呈现&QUOT;面积=&QUOT;参数查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆