1

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).

tereško
  • 58,060
  • 25
  • 98
  • 150
Roger Far
  • 2,178
  • 3
  • 36
  • 67

2 Answers2

3

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");}
ferventcoder
  • 11,952
  • 3
  • 57
  • 90
2

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.

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
  • 1
    I have been trying with RenderPartial, but I keep getting these errors: Argument 1: cannot convert from 'void' to 'System.Web.WebPages.HelperResult' – Roger Far Sep 05 '11 at 15:56