含局部模板,ASP.NET MVC [英] Including Partials, ASP.NET MVC

查看:100
本文介绍了含局部模板,ASP.NET MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建设我的第一个ASP.NET MVC应用程序,我有一些麻烦与部分景色。

I'm building my first ASP.NET MVC application and I am having some troubles with Partial Views.

如果我作为一个例子,希望把页脚作为一个部分我创建/Views/Shared/Footer.ascx一个MVC视图用户控件。 (我把它空的现在)

If I, as an example, want to put a "Footer" as a Partial I create an "MVC View User Control" in "/Views/Shared/Footer.ascx". (I leave it empty for now)

什么是它添加到我的布局的正确方法是什么?

What is the correct way for adding it to my Layout?

我曾尝试:

<%=Html.RenderPartial("Footer")%>

<%=Html.RenderPartial("~/Views/Shared/Footer.ascx")%>

对于每一个我得到一个异常:

For each one I get an exception:

CS1502:最好的重载方法
  难挡
  System.IO.TextWriter.Write(炭)'有
  一些无效参数

"CS1502: The best overloaded method match for 'System.IO.TextWriter.Write(char)' has some invalid arguments"

什么是处理在ASP.NET MVC?

What is the correct way to deal with partials in ASP.NET MVC?

推荐答案

在这种情况下,不使用的&lt;%=语法。只要使用在&lt;%%>语法。然后在你的例子中第一种形式应该工作。

In this case don't use the <%= syntax. Just use the <% %> syntax. Then the first form in your examples should work.

有关更多信息,请浏览:
http://bradwilson.typepad.com/blog/2008/08/partial -renderi.html

For more info, check here: http://bradwilson.typepad.com/blog/2008/08/partial-renderi.html

这篇关于含局部模板,ASP.NET MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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