[英]MVC 3 html helper with a template
I am trying to make a combination of a html helper and a Reder CSHTML. 我正在尝试结合使用HTML助手和Reder CSHTML。
In other words, how can I use a cshtml "template" with a html helper so I do not need to parse all the ugly HTML in the methods. 换句话说,如何将cshtml“模板”与html帮助器一起使用,因此无需解析方法中所有难看的HTML。
I am currently using @Html.Action but that is not preferable as it needs a working URL. 我目前正在使用@ Html.Action,但这不是可取的,因为它需要一个有效的URL。
@Html.RenderAction("GetThreads", "Forum")
public ActionResult GetThreads()
{
return new EmptyResult();
}
This gives the exception: 这给出了例外:
Argument 1: cannot convert from 'void' to 'System.Web.WebPages.HelperResult
Do I always need to add a route in the Global.asax file? 我是否总是需要在Global.asax文件中添加路由? Or are there ways to call Actions without it (like HTML helpers, but with a template file).
或者,有没有方法可以在没有它的情况下调用Action(例如HTML帮助器,但带有模板文件)。
I have been trying with RenderPartial, but I keep getting these errors: Argument 1: cannot convert from 'void' to 'System.Web.WebPages.HelperResult'
我一直在尝试使用RenderPartial,但始终出现以下错误:参数1:无法从“无效”转换为“ System.Web.WebPages.HelperResult”
Surround it with @{} 用@ {}括起来
@{Html.RenderPartial("_SomePartial");}
Use @Url.Action
to get the URL of an action. 使用
@Url.Action
获取操作的URL。 I think that is what you need. 我认为这就是您所需要的。
Or @Html.RenderPartial
or @Html.RenderAction
will spit out the view to the page. 或
@Html.RenderPartial
或@Html.RenderAction
会将视图吐出到页面。
EmptyResult
won't render a view. EmptyResult
将不会呈现视图。 That might be your problem. 那可能是你的问题。
You might be looking for RenderPartial
. 您可能正在寻找
RenderPartial
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.