In order to post back to Episerver page Mvc controller - you have to generate link to page's url. Keep in mind that it's not controller route in classical Mvc world. You can name page whatever you want and in order to hit that controller - you need to post to that url.
One of the easiest way to achieve this is to use Html helpers - like `@Html.ContentLink(page)`.
You will need to get access to current page (one that was serving this request). It's usually available in view model (if you are using AlloyTech sample site approach).
Hi validis,
if i use @Html.contentLink(startPage)
will the start page display or i get to the startpage controller?
the problem is i have some logic to do in the controller, so i want to get to the startpage controller with parameter i send to the controller from the view.
is it possible?
Most of the time controller is required to display the view - so short answer - yes, controller should be hit prior displaying view
You could do:
<a href="@Url.ContentUrl(ContentReference.StartPage).AppendUrlParameter("foo", "bar")">Lorem Ipsum</a>
Where AppendUrlParameter is a new extension method:
public static string AppendUrlParameter(this string url, string key, string value)
{
return url + (url.Contains("?") ? "&" : "?") + $"{key}={value.UrlEncode()}";
}
And get the markup:
<a href="/no/id4/?foo=bar">Lorem Ipsum</a>
Hi, i try to do somthing that is very simple in mvc, but now, with episerver i have some problems:
in the view, while clicking, i want to redirect to epicontroller and pass parameter.
in mvc i do something like
@foreach (var element in Model)
{
<li> @Html.ActionLink(element.categoryName,"MyActionResult", "MyController")</li>
}
in mvc+epiServer, i already created the relevant epi page, how can i redirect to its epi controller with parameter?
thank you