Reputation: 1269
I am using @Html.Action to call contoller action to return a string. I want to save the string to a variable inside razor as it is comma-seperated.
@Html.Action("GetCategories", new { SP = @ViewBag.Name, SD = "Cad" }).ToString();
//@String s = save above string in here
//@string[] arrS = s.Split(',');
@String test = @Html.Action(......) //tried this but does NOT work.
Public ActionResult GetCategories(string SP, string SD)
{
//Code missing
return Content(return "sugar");
}
How can I save the Html.Action returned data to a string ?
Upvotes: 0
Views: 2905
Reputation: 51
Url.Action only/always returns a Url. Not sure how this selected answer solved the problem for you unless you DID want the Url (e.g. /Controller/Action/...).
Seems Html.Action was what you wanted all along. It would return the contents "sugar" if you simply had your return coded like this;
return Content("sugar");
You can display it right on the page or use the suggested syntax from "Mark" to save it to a varible
Upvotes: 1
Reputation: 788
This works for me, just tried in a local MVC project:
@{
string test;
test = @Url.Action("actionName");
}
Upvotes: 2