admin管理员组文章数量:1414604
I have ,MyPartialView.cshtml':
<div id="partialDiv">some content</div>
an 'index.cshtml':
<div id="mainDiv"> </div>
and an 'index.js'.
The 'index.js' should do sth like:
$('mainDiv').html($('#partialDiv'))
to put the partial view into the main div.
(writing @<text> <div> @Html.Partial("MyPartialView")</div></text>)
in my .cshtml works, but I need to change the content dynamically. Therefore, I thought maybe there is an equivalent in JavaScript for 'Html.Partial
'
(Or is there another way to get a Partial View without an AJAX Call)
I have ,MyPartialView.cshtml':
<div id="partialDiv">some content</div>
an 'index.cshtml':
<div id="mainDiv"> </div>
and an 'index.js'.
The 'index.js' should do sth like:
$('mainDiv').html($('#partialDiv'))
to put the partial view into the main div.
(writing @<text> <div> @Html.Partial("MyPartialView")</div></text>)
in my .cshtml works, but I need to change the content dynamically. Therefore, I thought maybe there is an equivalent in JavaScript for 'Html.Partial
'
(Or is there another way to get a Partial View without an AJAX Call)
Share Improve this question asked Oct 25, 2018 at 15:29 thestruggleisrealthestruggleisreal 1,3153 gold badges16 silver badges33 bronze badges 02 Answers
Reset to default 3@Html.Partial("MyPartialView")
used only to render single partial view file (also with @Html.RenderPartial()
). You can use AJAX to call controller action which returns partial view:
AJAX Request
$.ajax({
type: 'GET',
url: '@Url.Action("ActionName", "ControllerName")',
// other settings
success: function (result) {
$('mainDiv').html(result);
}
});
Controller Action
[HttpGet]
public ActionResult ActionName()
{
// do something
return PartialView("MyPartialView");
}
Note that there's no equivalent of calling partial view in JS, because you need to make request to server which can't be simply handled by standard JS functions.
cshtml
files are rendred in server side. you can't load it using just JavaScript. the perfect way is using Ajax by calling an Action that return your partial view
本文标签: How to put a Partial View into a div in JavaScript (with jQuery)Stack Overflow
版权声明:本文标题:How to put a Partial View into a div in JavaScript (with jQuery) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745193859a2647041.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论