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

Forums / Developing with Sitefinity / MVC Widget Hybrid Mode on Home Page

MVC Widget Hybrid Mode on Home Page

4 posts, 0 answered
  1. heads
    heads avatar
    6 posts
    Registered:
    30 Aug 2006
    20 Jun 2014
    Link to this post

    I'm having issues with a MVC widget. It's a Registration form that sits on the home page.

    The controller is similar to:

    01.[ControllerToolboxItem(Name = "RegisterForInterestMvc", Title = "RegisterForInterestMvc", SectionName = "MvcWidgets"), Telerik.Sitefinity.Web.UI.ControlDesign.ControlDesigner(typeof(Em2.SitefinityWebApp.WidgetDesigners.RegisterForInterestMvc.RegisterForInterestMvcDesigner))]
    02.    public class RegisterForInterestMvcController : Controller
    03.    {
    04.        /// <summary>
    05.        /// Gets or sets the message.
    06.        /// </summary>
    07.        [Category("String Properties")]
    08.        public string Message { get; set; }
    09. 
    10.        /// <summary>
    11.        /// This is the default Action.
    12.        /// </summary>
    13.        public ActionResult Index()
    14.        {
    15.            var model = new RegisterForInterestMvcModel();
    16.            if (string.IsNullOrEmpty(this.Message))
    17.            {
    18.                model.Message = "Hello, World!";
    19.            }
    20.            else
    21.            {
    22.                model.Message = this.Message;
    23.            }
    24. 
    25.            return View("Default", model);
    26.        }
    27. 
    28.        [HttpPost]
    29.        public ActionResult Index(RegisterForInterestMvcModel model)
    30.        {
    31.            //do stuff here
    32. 
    33.            return View("Success", model);
    34.        }
    35.    }

    The Default.cshtml and Success.html files are under the ~/Views/RegisterForInterestMvc folder in the solution.

    Two issues occur:

    1. When I access the page from http://mywebsite the post works but it is redirect to the Success view with no master page or theming
    2. When I access the page from the Home page link the navbar I get a 404 error "Can't find http://mywebsite /index?<somequerystringhere>

    The only way I can route to my success page is by changing the Post action to 

    1.[HttpPost]
    2.public ActionResult Index(RegisterForInterestMvcModel model)
    3.{
    4.    //do stuff here
    5. 
    6.    return Redirect("~/Index/Success?"+queryStringBuilt);
    7.}

     

    Which results in a page url which is ugly http://mywebsite/index/success?querystring=blah

    How can I create more user friendly routes in Hybrid mode?

  2. Boyko Karadzhov
    Boyko Karadzhov avatar
    56 posts
    Registered:
    05 Dec 2016
    20 Jun 2014
    Link to this post
    Hi Craig,

    You can use an attribute like [ActionName("Success")] on any action to make it listen for that route value.

    Another way to control what happens it to override the protected method called HandleUnknownAction and implement logic that decides what to render based on whatever action is requested.

    Regards,
    Boyko Karadzhov
    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
     
  3. heads
    heads avatar
    6 posts
    Registered:
    30 Aug 2006
    20 Jun 2014 in reply to Boyko Karadzhov
    Link to this post

    Thanks for the information it certainly helped on non home pages but the issue on the home page still persists with both suggestions.

    When I click home from the navigation menu and then click submit the form posts to http://localhost:60876/Index?sf_cntrl_id=ctl00$cph_main$C003 and I get a 404

  4. Svetoslav Petsov
    Svetoslav Petsov avatar
    456 posts
    Registered:
    24 Sep 2012
    24 Jun 2014
    Link to this post
    Hi Craig,

    This is a known issue at our end and we already have it logged internally.
    However, I made a feedback item for you in our feedback portal, so that you can track the issue yourself:
    http://feedback.telerik.com/Project/153/Feedback/Details/131773-mvc-widget-that-performs-redirect-on-httppost-doesnt-work-if-you-access-the-hom
    Let me know if I can be of further help to you.

    Regards,
    Svetoslav Petsov
    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
     
4 posts, 0 answered