Copied to clipboard

Flag this post as spam?

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


  • Tom Engan 430 posts 1173 karma points
    Jul 07, 2017 @ 14:20
    Tom Engan
    0

    Change partial view with a link button from another partial view

    Anyone who knows how to change a single partial view in a page with a link from the same page, inside another form? In this example, I want to change partial view from CreateHikingDestination to UpdateHikingDestination, but the link is on the inside of another partial view: ListHikingDestinations.

    enter image description here

    For example, if I use this from the Endre button (same as update) inside partial view ListHikingDestinations:

    @ Html.ActionLink ("Endre", "ReadHikingDestinationById", new {id = @ hikingdestination.Id, controller = "HikingDestinationSurface"})
    

    It fetches the right action named ReadHikingDestinationById(id) from the HikingDestinationSurfaceController

    [HttpGet]
    Public ActionResult ReadHikingDestinationById (int Id)
    {
        ViewBag.MessageToUser = "Change Trip Destination";
    
        HikingDestinationViewModel model = new HikingDestinationViewModel ();
        Was hikingdestination = HikingDestinations.GetById (Id);
    
        Model.HikingCode = hikingdestination.HikingCode;
        Model.StartDate = hikingdestination.StartDate;
        Model.ListOfHikingDestinations = ListHikingDestinations (1122);
        Model.Title = hiking destination.Title;
    
        Return PartialView ("UpdateHikingDestination", model);
    }
    

    The code find the right form with the id, but it's only shows this partial view, not the entire page (no surprise, realy).

    The obvious option is to create a new page of course, but I think switching partial views may be useful sometimes - like now when I want to keep all information about hiking destinations on the same pagename.

  • Tom Engan 430 posts 1173 karma points
    Aug 01, 2017 @ 15:13
    Tom Engan
    0

    I think there is a easy way to redirect to the same page, same surfacecontroller, and use another Action with Id (named ReadHikingDestinationById (int Id)) - from the update and delete buttons, maybe with @Html.ActionLink, but how?

  • Tom Engan 430 posts 1173 karma points
    Aug 04, 2017 @ 09:29
    Tom Engan
    0

    So, how do we normally swap one of several partial views (all via macros), on the same page (from a textlink from another partial view)?

    This together with an id value to retrieve a single record from a database into the new update partial view for editing.

Please Sign in or register to post replies

Write your reply to:

Draft