Reputation: 2384
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).
Upvotes: 1
Views: 1407
Reputation: 12611
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");}
Upvotes: 3
Reputation: 191058
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
.
Upvotes: 2