Copied to clipboard

Flag this post as spam?

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


  • Lander Debeuf 23 posts 125 karma points
    Nov 22, 2018 @ 23:39
    Lander Debeuf
    0

    Update part of a CRUD operation with Umbraco 7.2

    I have a partial view to edit an object retrieved from the database. I would like to update that object. How do i get the correct object in that partial view with umbraco?

    @model mySite.WEB.Modules.Locations.ViewModels.LandenEditViewModel
    
    <form id="land_edit" class="form-horizontal form-label-left" novalidate>
        <div class="form-group">
            @Html.LabelFor(x => x.Land.Naam)
            @Html.EditorFor(x => x.Land.Naam)
            @Html.ValidateFor(x => x.Land.Naam)
        </div>
        <div class="form-group">
            @Html.LabelFor(x => x.Land.Code)
            @Html.EditorFor(x => x.Land.Code)
            @Html.ValidateFor(x => x.Land.Code)
        </div>
    
        <div class="form-group">
            <div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-3">
                <button class="btn btn-success" type="submit">Opslaan</button>
            </div>
        </div>
    </form>
    

    The Umbraco template is as follows

    @inherits UmbracoViewPage<mysite.DOMAIN.Models.Edit>
    
    @{
        Layout = "Master.cshtml";
    }
    
    @Html.Action("LandenEdit", "Locations")
    

    The surface controller that is taking care of this

    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using Umbraco.Web.Mvc;
    
    namespace mysite.WEB.Modules.Locations
    {
        public class LocationsController : SurfaceController
        {
            private readonly LocationService _locationService;
    
            public LocationsController()
            {
                _locationService = new LocationService(new mysite.DATA.CustomDbContext());
            }
    
            public ActionResult LandenLijst()
            {
                ViewModels.LandenLijstViewModel model = new ViewModels.LandenLijstViewModel();
                model.Landen = _locationStore.GetLanden();
    
                return PartialView("_LandenLijst", model);
            }
    
            public ActionResult EditLand(int id)
            {
                ViewModels.LandenEditViewModel model = new ViewModels.LandenEditViewModel();
                model.Land = _locationStore.GetLanden().FirstOrDefault(x => x.LandId == id);
    
                return PartialView("_LandenEdit", model);
            }
    
            [HttpPost]
            public ActionResult EditLandPost(ViewModel model)
            {
                 //Saving logic
            }
        }
    }
    

    The problem i am facing is that i cannot seem to get a link to the Edit method passing the id value from the listview. How can i do this in umbraco, my page viewed in the browser, showing the template of the document type, in his turn calling the partial view and passing the id, or the model or whatever the best practice should be to achieve this.

    Any help would be deeply apreciated.

    How i am talking to the custom database is not the issue here, i really need the Umbraco/MVC/... way to get all the data to the correct controller.

    Thx

Please Sign in or register to post replies

Write your reply to:

Draft