MVC widgets

Posted by Community Admin on 04-Aug-2018 08:52

MVC widgets

All Replies

Posted by Community Admin on 15-Sep-2015 00:00

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

Posted by Community Admin on 18-Sep-2015 00:00

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);
        
    

And here is the markup of the controller's view where I added the @Html.ActionLink():

@model SitefinityWebApp.Mvc.Models.LogoutMVCWidgetModel
 
<h1>
    @Html.Raw(Model.Message)
</h1>
 
@Html.ActionLink("Click here to logout", "Logout")

I am also sending attached a short video for your convenience demonstrating the results.

Can you please try to use the same approach on your side?

Regards,
Sabrie Nedzhip
Telerik
 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

This thread is closed