简体   繁体   English

MVC.Net操作链接可部分更新

[英]MVC.Net Action link to update partial

I'm using partial views within an MVC.Net website to display content from a database. 我在MVC.Net网站中使用局部视图来显示数据库中的内容。 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. 理想情况下,我希望能够在需要任何内容​​的任何页面上放置@Html.Action 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. 但是用部分替换为“ Edit ”状态替代。

Obviously at the moment, putting an ActionLink in the partial navigates away from the current page and displays the Edit view full screen. 显然,目前,将ActionLink放置在部分视图中会远离当前页面,并全屏显示“编辑”视图。

The Controller "SiteCMSController" looks up the id from the db/cache and inserts it in the page. 控制器“ SiteCMSController”从数据库/缓存中查找ID,并将其插入页面中。 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 使用一些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 :) UpdateTargetId,这是您要存储的部分内容,您必须将ID为“ someDiv”的div或其他ofc :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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