Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 3 布局导航上的MVC3操作链接_Asp.net Mvc 3_Razor - Fatal编程技术网

Asp.net mvc 3 布局导航上的MVC3操作链接

Asp.net mvc 3 布局导航上的MVC3操作链接,asp.net-mvc-3,razor,Asp.net Mvc 3,Razor,我正在编写我的第一个MVC3 web应用程序之一。我在SiteLayout.cshtml中对导航进行了类似的编码 <table width="950" border="0" align="center" cellpadding="0" cellspacing="0" style="height: 40px;"> <tr align="center"> <td>@Html.ActionLink(

我正在编写我的第一个MVC3 web应用程序之一。我在SiteLayout.cshtml中对导航进行了类似的编码

<table width="950" border="0" align="center" cellpadding="0" cellspacing="0" style="height: 40px;">
            <tr align="center">
                <td>@Html.ActionLink( 
                    "Home", 
                    "Index", 
                    null, 
                    new { @class= "link1"}) 
                </td>
                <td><img src="@Url.Content("~/Content/images/img3.gif")" alt="" width="2" height="40" /></td>
                <td>@Html.ActionLink( 
                    "Events", 
                    "Events", 
                    null, 
                    new { @class= "link1"}) 
                </td>
                <td><img src="@Url.Content("~/Content/images/img3.gif")" alt="" width="2" height="40" /></td>
                <td>@Html.ActionLink( 
                    "Membership", 
                    "Membership", 
                    null, 
                    new { @class= "link1"}) 
                </td>
                <td><img src="@Url.Content("~/Content/images/img3.gif")" alt="" width="2" height="40" /></td>
                <td>@Html.ActionLink( 
                    "Photos", 
                    "Photos", 
                    null, 
                    new { @class= "link1"} )
                </td>
                <td><img src="@Url.Content("~/Content/images/img3.gif")" alt="" width="2" height="40" /></td>
                <td>@Html.ActionLink( 
                    "About Us", 
                    "AboutUS", 
                    null, 
                    new { @class= "link1"})
                </td>
                <td><img src="@Url.Content("~/Content/images/img3.gif")" alt="" width="2" height="40" /></td>
                <td>@Html.ActionLink( 
                    "Contact Us", 
                    "ContactUs", 
                    null, 
                    new { @class= "link1"})</td>
            </tr>
        </table>``
即使操作链接当前位于注册控制器上,我如何使其指向站点控制器?我已经尝试将“Site”放在我当前具有空值的位置。如果我这样做,那么它工作正常,但显示此url

http://localhost:49365/Site/Photos?class=link1
css类不再应用于链接。我希望的url是相同的url

如果我使用默认站点控件中的链接,将显示该链接。任何指导都将不胜感激

许多祝福


Jared

这只是一个过载解决方案的问题。可以在上找到所有重载的列表

如前所述,您最终使用
HtmlHelper、string、string、object、object
,您的第一个
null
routeValue
,因此匿名对象是您的
htmlAttributes

您在正确的轨道上通过
“站点”
而不是
null
来获得正确的控制器,但这会让您使用
HtmlHelper、string、string、object、object
。第一个对象仍然是
routeValues
,这解释了为什么它会变成查询字符串

要指定
htmlAttributes
,可以继续为
routeValue传递
null
占位符

@Html.ActionLink( 
                "Photos", 
                "Photos",
                "Site", 
                null, 
                new { @class= "link1"} )
或者你曾经


这只是一个解决问题的方法。可以在上找到所有重载的列表

如前所述,您最终使用
HtmlHelper、string、string、object、object
,您的第一个
null
routeValue
,因此匿名对象是您的
htmlAttributes

您在正确的轨道上通过
“站点”
而不是
null
来获得正确的控制器,但这会让您使用
HtmlHelper、string、string、object、object
。第一个对象仍然是
routeValues
,这解释了为什么它会变成查询字符串

要指定
htmlAttributes
,可以继续为
routeValue传递
null
占位符

@Html.ActionLink( 
                "Photos", 
                "Photos",
                "Site", 
                null, 
                new { @class= "link1"} )
或者你曾经


作为非主题提示,请对视图中的图像使用CSS。通过这种方式,您可以避免每个标记都向服务器发出GET请求,作为非主题提示,对视图中的图像使用CSS。通过这种方式,您可以避免每个标记向服务器发出GET请求谢谢这篇文章指导我更彻底地理解html helper ActionLink()的重载。我最终做了以下几件事@ActionLink(“联系我们”,“联系我们”,new{controller=“Site”},htmlAttributes:new{@class=“link1”})感谢您这篇文章指导我更彻底地理解Html助手ActionLink()的重载。我最终做了以下几件事@ActionLink(“联系我们”,“联系我们”,new{controller=“Site”},htmlAttributes:new{@class=“link1”})
@Html.ActionLink( 
                "Photos", 
                "Photos",
                "Site", 
                htmlAttributes: new { @class= "link1"} )