MVC 3 HTML辅助使用模板 [英] MVC 3 html helper with a template
问题描述
我试图让一个HTML帮助和瑞德CSHTML的组合。
I am trying to make a combination of a html helper and a Reder CSHTML.
在换句话说,我怎么可以用一个CSHTML的模板用HTML帮助,所以我并不需要解析所有丑陋的HTML中的方法。
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.
我目前使用的@ Html.Action但它需要一个工作URL不是preferable。
I am currently using @Html.Action but that is not preferable as it needs a working URL.
@Html.RenderAction("GetThreads", "Forum")
public ActionResult GetThreads()
{
return new EmptyResult();
}
这给出了异常:
Argument 1: cannot convert from 'void' to 'System.Web.WebPages.HelperResult
我总是需要在Global.asax文件中添加路由?或者有没有办法来调用操作没有它(如HTML佣工,但有一个模板文件)。
Do I always need to add a route in the Global.asax file? Or are there ways to call Actions without it (like HTML helpers, but with a template file).
推荐答案
使用 @ Url.Action
来得到一个动作的URL。我认为这是你所需要的。
Use @Url.Action
to get the URL of an action. I think that is what you need.
或 @ Html.RenderPartial
或 @ Html.RenderAction
会吐出视图页面。
EmptyResult
将不渲染视图。这可能是你的问题。
EmptyResult
won't render a view. That might be your problem.
您可能会寻找的RenderPartial
。
这篇关于MVC 3 HTML辅助使用模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!