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).
Use
@Url.Actionto get the URL of an action. I think that is what you need.Or
@Html.RenderPartialor@Html.RenderActionwill spit out the view to the page.EmptyResultwon’t render a view. That might be your problem.You might be looking for
RenderPartial.