+1-888-365-2779
Try Now
More in this section

MVC widgets

2 posts, 0 answered
  1. Andrey
    Andrey avatar
    4 posts
    Registered:
    25 Feb 2015
    15 Sep 2015
    Link to this post

    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

  2. Sabrie Nedzhip
    Sabrie Nedzhip avatar
    534 posts
    Registered:
    02 Dec 2016
    18 Sep 2015
    Link to this post
    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
     
2 posts, 0 answered