Copied to clipboard

Flag this post as spam?

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


  • Jorge 37 posts 119 karma points
    Sep 07, 2016 @ 15:45
    Jorge
    0

    Umbraco Temporary Page

    Hi I was building an Umbraco 7.4.3 site, and I was ended up to this situation. I have a node structure inside umbraco like this. see screenshot http://screencast.com/t/j41OnJDkgn

    Ok, so I have a Student and Teacher node under Home. Now lets focus on Student.

    The Student node will show a detail about student.

    Now

    I want to have a page where I can edit a Student, "I want a separate page (not popup) linking to a page where I can edit a student", something like a /edit-student/?id=2.

    But in order do that I will end up in a structure like this, see screenshot http://screencast.com/t/85j7qCmcD

    See? I have an extra node EditStudent just to have a page where I can edit student, I can call this page by /Student/EditStudent/?id=2

    But I dont want to have this node "EditStudent", I feel it was making my node structure dirty.

    I want a solution that I can still have a url like this /Student/EditStudent/?id=2 but I dont want to see a node "EditStudent" under Student or somewhere else inside my umbraco.

    Is this possible to happen? something like a virtual url (but not aspx) pages.

  • Alex 8 posts 131 karma points
    Sep 07, 2016 @ 20:58
    Alex
    100

    What I think you are looking for is the alternate template feature that Umbraco provides.

    You can add another template to the Umbraco backoffice which is called "Edit", and when you append that to the end of the url (and there is no node as a child with the same name), you will get that alternate template instead of the default one.

    In your example it would be "/student/edit?id=2"

    Then just use a surface controller to render your student edit form and and handle the submission.

    Edit.cshtml:

    @Html.Action("Render", "StudentForm", new {id = Request.Params["id"]})
    

    StudentFromController.cs:

    public class StudentFormController : SurfaceController
    {
        [ChildActionOnly]
        public ActionResult Render(int id) {
            var studentViewModel = new StudentFormModel();        
    
            // Get the student to render
    
            return PartialView("~/Views/Partials/StudentForm.cshtml", studentViewModel );
        }
    
        [HttpPost]
        public ActionResult Submit(StudentFormModel model) {
            if (!ModelState.IsValid) {
                return CurrentUmbracoPage();
            }
    
            // Do saving stuff
    
            return RedirectToCurrentUmbracoPage();
        }}
    
  • Jorge 37 posts 119 karma points
    Sep 08, 2016 @ 08:37
    Jorge
    0

    Brilliant!! but how did you know that? was it on Umbraco doc? this was I am looking for such a long time. No node required, just a template.

  • Alex 8 posts 131 karma points
    Sep 08, 2016 @ 13:40
    Alex
    1

    It's burred in the documentation somewhere but references a web forms implementation.

    http://umbraco.tv/videos/umbraco-v7/implementor/fundamentals/templating/alt-template/documentation

    I learned about it when I went to an Umbraco training. It's a great resource if you have the chance to go!

Please Sign in or register to post replies

Write your reply to:

Draft