admin管理员组文章数量:1355529
I have a web page with a couple of view ponents, when I click on these ponents I open a simple editor for it, see image below. If I edit the text and hit enter, I would like to rerender the view ponent and not the hole page. Is it possible to invoke a view ponent using javascript to get this behaviour?
I have a web page with a couple of view ponents, when I click on these ponents I open a simple editor for it, see image below. If I edit the text and hit enter, I would like to rerender the view ponent and not the hole page. Is it possible to invoke a view ponent using javascript to get this behaviour?
Share Improve this question asked Feb 17, 2015 at 18:10 marcusmarcus 10.1k9 gold badges59 silver badges110 bronze badges2 Answers
Reset to default 6With updates, you should now be able to do this with asp core. You can return a ViewComponent from an IActionResult, then just call it with jQuery:
[Route("text-editor")]
public IActionResult TextEditor()
{
return ViewComponent("TextEditorViewComponent");
}
Then this can be called from your View with something as simple as this:
function showTextEditor() {
// Find the div to put it in
var container = $("#text-editor-container");
$.get("text-editor", function (data) { container.html(data); });
}
If you need to pass parameters to the ViewComponent you can do so in the IActionResult (maybe they trickle through from the View to there, to the view ponent, etc).
This is not possible today but you could build a standard proxy for viewponents if you'd like though (similarly you could build a proxy to partial views). e.g. you a catchall attribute route on an action.
本文标签: aspnet coreInvoke ViewComponent using javascriptStack Overflow
版权声明:本文标题:asp.net core - Invoke ViewComponent using javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743996789a2573135.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论