Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
689 views
in Technique[技术] by (71.8m points)

asp.net mvc - T4MVC @Url.Action(MVC.Controller.Action()) Renders "?Area=" Parameter in QueryString

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

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

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>
           ... 

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>
               ...

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I solve this issue in a very easy way, simply by adding to all routes that are not in area empty area route like this:

routes.MapRoute(
"Default",
"{controller}/{action}/{i?d}",
new { controller = "Home", action = "Index", area = "", id = UrlParameter.Optional });

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...