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
  • 56,151
  • 24
  • 92
  • 147
Roger Far
  • 2,040
  • 3
  • 34
  • 63

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
  • 10,640
  • 2
  • 51
  • 83
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
  • 174,715
  • 42
  • 343
  • 413
  • 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