Need to call an action in custom controller - RenderMvcController
I'm new to Umbraco. I wasn't sure if I should use a surface controller or a custom controller for this scenario. I decided on custom controller mainly because I need the action to get called even if someone copies the action link to the browser.
I want to change the language in a cookie:
public class HeaderController : RenderMvcController
{
const string cookieName = "langCookie";
public override ActionResult Index(RenderModel model)
{
//Do some stuff here, then return the base method
return base.Index(model);
}
[HttpPost]
public ActionResult LanguageCookieSet(RenderModel pModel, string pLang)
{
var langCookie = new HttpCookie(cookieName);
var now = DateTime.Now;
if (!string.IsNullOrWhiteSpace(pLang))
{
langCookie.Value = pLang;
langCookie.Expires = now.AddDays(60);
// Add the cookie.
Response.Cookies.Add(langCookie);
}
return base.Index(pModel);
}
[HttpGet]
public string LanguageCookieGet()
{
var langCookie = new HttpCookie(cookieName);
langCookie = Request.Cookies[cookieName];
return langCookie.ToString() ?? string.Empty;
}
}
On the view I tried calling it using:
Url.Action like so: (didn't work)
@Html.Action("LanguageCookieSet", "Header", new { pModel = this, pLanguage = "en" })"
Then I tried: (also doesn't work)
Error:
No route in the route table matches the supplied values.
This is a tricky thing. The Methods of the RenderMvcController MUST match a template. In this case you NEED to have templates called LanguageCookieSet and LanguageCookieGet. This is not what you were planning I guess.
Need to call an action in custom controller - RenderMvcController
I'm new to Umbraco. I wasn't sure if I should use a surface controller or a custom controller for this scenario. I decided on custom controller mainly because I need the action to get called even if someone copies the action link to the browser.
I want to change the language in a cookie:
On the view I tried calling it using: Url.Action like so: (didn't work) @Html.Action("LanguageCookieSet", "Header", new { pModel = this, pLanguage = "en" })"
Then I tried: (also doesn't work)
Error: No route in the route table matches the supplied values.
Any suggestions will be very much appreciated.
Hi,
This is a tricky thing. The Methods of the RenderMvcController MUST match a template. In this case you NEED to have templates called LanguageCookieSet and LanguageCookieGet. This is not what you were planning I guess.
It's probably easier to override a PrepareContentRequest method. Or create a contentFinder.
is working on a reply...