MVC widgets
HI all. I am implementing a custom login widget on MVC. There is a Logout() method inside the UserController. Then I have a header widget, that is part of a sitefinity module. So for instance I want to call from custom module widget my Logout() method. I have tried to use @Html.ActionLink("logout", "Logout", "User" ) but nothing works.
Could you please recommend me how to implement such logic.
Best regards, Andrew
Hello Andrew,
I tested this on my side and I managed to redirect to the Logout() action in the controller using @Html.ActionLink("LinkText", "YourActionName")
Here is the controller I used on my side:
using System;using System.ComponentModel;using System.Linq;using System.Web.Mvc;using Telerik.Sitefinity.Mvc;using SitefinityWebApp.Mvc.Models;namespace SitefinityWebApp.Mvc.Controllers [ControllerToolboxItem(Name = "LogoutMVCWidget", Title = "LogoutMVCWidget", SectionName = "MvcWidgets"), Telerik.Sitefinity.Web.UI.ControlDesign.ControlDesigner(typeof(SitefinityWebApp.WidgetDesigners.LogoutMVCWidget.LogoutMVCWidgetDesigner))] public class LogoutMVCWidgetController : Controller /// <summary> /// Gets or sets the message. /// </summary> [Category("String Properties")] public string Message get; set; /// <summary> /// This is the default Action. /// </summary> public ActionResult Index() var model = new LogoutMVCWidgetModel(); if (string.IsNullOrEmpty(this.Message)) model.Message = "Hello, World!"; else model.Message = this.Message; return View("Default", model); /// <summary> /// This is the default Action. /// </summary> public ActionResult Logout() var model = new LogoutMVCWidgetModel(); model.Message = "Here is the Logout() action from the controller"; return View("Default", model); @model SitefinityWebApp.Mvc.Models.LogoutMVCWidgetModel<h1> @Html.Raw(Model.Message)</h1>@Html.ActionLink("Click here to logout", "Logout")