简体   繁体   中英

MVC.Net Action link to update partial

I'm using partial views within an MVC.Net website to display content from a database. I want to be able to offer as WYSIWYG as possible an interface for modifying that content.

Ideally I'd like to be able to put an @Html.Action in whatever page I need some content on. Then automatically offer an " Edit " link for authenticated users.

Once the edit link is clicked, I want to show the same page as they were already on. (From a different controller). But with the partial replaced with it's " Edit " state alternative.

Obviously at the moment, putting an ActionLink in the partial navigates away from the current page and displays the Edit view full screen.

The Controller "SiteCMSController" looks up the id from the db/cache and inserts it in the page. If the user is an admin, it adds an edit link.

<div>
    @Html.Action("_Content", "SiteCMS", new { id = 1 })
</div>

results in

<div>
    Some text pulled in from the database.
    <br>
    <a href="~/SiteCMS/Edit/1">Edit this content</a>
</div>

(Off the top of my head code.)

use some ajax

<div>
    @Ajax.Actionlink("_Content", "SiteCMS", new { id = 1}, new AjaxOptions {       UpdateTargetId = "someDiv"})
</div>

UpdateTargetId, this is were your partial will be stored, you have to make a div with the id "someDiv", or something else ofc :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM