Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ronak Panchal 71 posts 230 karma points
    Nov 30, 2015 @ 13:12
    Ronak Panchal
    0

    Need Help on Surface Controller

    Hello all, I create a project in visual studio and install umbraco via nuget. then Customize the database and install umbraco then created one table in database and try to insert values using surface controller but I'm not able to call the controller.

    Below code Shows the Model

     public class test
    {
        public string Title { get; set; }
        public string Genre { get; set; }
        public int Year { get; set; }
    }
    

    below code shows the controller

    [HttpPost]
        public ActionResult CreateComment(test model)
        {
           //Data insertion code goes here.
           return PartialView("ContactForm", "Movie");
        }
    

    After that i created one partial view.

    @Model DbIWithUmbraco.Models.test
    @using (Html.BeginForm("CreateComment","MovieSurface"))
    {
        <div>
            @Html.LabelFor(Model => Model.Title)
        </div>
        <div>
            @Html.TextBoxFor(Model => Model.Title)
        </div>
        <div>
            @Html.LabelFor(x => Model.Genre)
        </div>
        <div>
            @Html.TextBoxFor(x => Model.Genre)
        </div>
        <div>
            @Html.LabelFor(x => Model.Year)
        </div>
        <div>
            @Html.TextAreaFor(x => Model.Year)
        </div>
        <input type="submit" />
    }
    

    After i create template and call this Partial view.

    But i m not able to call the controller.

    Any help would be appreciated.

    Thanks

    Ronak Panchal.

  • Mark Bowser 273 posts 860 karma points c-trib
    Nov 30, 2015 @ 16:02
    Mark Bowser
    0

    Does your SurfaceController inherit from SurfaceController? Can you add the class definition of your SurfaceController?

  • Ronak Panchal 71 posts 230 karma points
    Dec 01, 2015 @ 04:15
    Ronak Panchal
    0

    hello mark,

    Thanks for sharing your point of view !

    Yes my SurfaceController inherit from SurfaceController.

    Below is my full code

    public class MovieSurfaceController : Umbraco.Web.Mvc.SurfaceController
        {
            // GET: Movie
            public ActionResult Index()
            {
                return View();
            }
    
            [HttpPost]
            public ActionResult CreateComment(Company model)
            {
                //model not valid, do not save, but return current Umbraco page
                if (!ModelState.IsValid)
                {
                    //Perhaps you might want to add a custom message to the ViewBag
                    //which will be available on the View when it renders (since we're not 
                    //redirecting)          
                    return CurrentUmbracoPage();
                }
    
                //Add a message in TempData which will be available 
                //in the View after the redirect 
                TempData.Add("CustomMessage", "Your form was successfully submitted at " + DateTime.Now);
    
                //redirect to current page to clear the form
                //return RedirectToCurrentUmbracoPage();
                return RedirectToUmbracoPage(1059);
            }
    
        }
    
  • Nicholas Westby 2054 posts 7100 karma points c-trib
    Dec 01, 2015 @ 04:46
    Nicholas Westby
    0

    Rather than Html.BeginForm, try Html.BeginUmbracoForm.

    That will inject a hidden field with a name of "ufprt" that helps Umbraco's routing engine fine the appropriate surface controller.

  • Ronak Panchal 71 posts 230 karma points
    Dec 01, 2015 @ 05:15
    Ronak Panchal
    0

    Hello Nicholas,

    i already try Html.BeginUmbracoForm

    But not able to call the controller.

    Thanks, Ronak Panchal

  • David Brendel 792 posts 2970 karma points MVP 3x c-trib
    Dec 01, 2015 @ 07:37
    David Brendel
    0

    Hi Ronak,

    you should definitly use BeginUmbracoForm as it's the right way to call the controller.

    The code you posted seems correct to me. Will try to check if I find some old code if mine to share.

    Regards David

  • Ronak Panchal 71 posts 230 karma points
    Dec 01, 2015 @ 12:26
    Ronak Panchal
    0

    Hi David,

    Thanks in advance that you could try to check and find some code related to surface controller and find out that what i m missing in my code.

    Any help would be appreciated !

    Regards, Ronak.

Please Sign in or register to post replies

Write your reply to:

Draft