简体   繁体   中英

MVC 3 html helper with a template

I am trying to make a combination of a html helper and a 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.

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();
}

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? Or are there ways to call Actions without it (like HTML helpers, but with a template file).

I have been trying with RenderPartial, but I keep getting these errors: Argument 1: cannot convert from 'void' to 'System.Web.WebPages.HelperResult'

Surround it with @{}

@{Html.RenderPartial("_SomePartial");}

Use @Url.Action to get the URL of an action. I think that is what you need.

Or @Html.RenderPartial or @Html.RenderAction will spit out the view to the page.

EmptyResult won't render a view. That might be your problem.

You might be looking for RenderPartial .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM