Reputation:
I have a controller that will be shared with three different pages in sitefinity. The API will take in different parameters for each of the three pages. Is there a page setting values I can set the parameters in and be able to use then in the Controller?
Upvotes: 0
Views: 162
Reputation: 3793
You can add public properties to the controller and these will appear in the designer of the widget - when you "Edit" the widget in the backend you can set different values to these properties.
So, each of the 3 pages can set unique values there.
Example:
[ControllerToolboxItem(Name = "TemporaryRedirectController", Title = "Temporary Redirect", SectionName = "Custom Widgets", CssClass = "sfMvcIcn")]
public class TemporaryRedirectController : Controller
{
public string RedirectUrl { get; set; }
public ActionResult Index()
{
if (SystemManager.IsDesignMode)
{
return Content($"This widget will 302 redirect to {RedirectUrl}");
}
if (!this.RedirectUrl.IsNullOrEmpty())
{
return Redirect(this.RedirectUrl);
}
return new EmptyResult();
}
}
In the sample above, you can drag this widget to 3 different pages and when you edit it, you will be able to set a different value to the RedirectUrl field.
Upvotes: 1