MVC脚本无法在< div>内使用 [英] MVC scripts not able to use inside a <div>

查看:59
本文介绍了MVC脚本无法在< div>内使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友们,





我在div中使用我的捆绑脚本时遇到问题。

我的主要布局中有一些脚本,其中一个是:



Dear friends,


I have a issue with using my bundle scripts inside a div.
I have inside my main layout some scripts one of those is:

@Scripts.Render("~/bundles/menus")





在布局中我有一个没有HTML内容的div:





Inside the layout I have a div without html content:

<div id="ajaxResponse" ActieID="0" relatieID="0"></div>





我用ajax帖子填写这个内容。







I fill this content with a ajax post.


$("#action").click(function () {
     var id = $('#ajaxResponse').attr('data');
     $.ajax(
         {
             type: 'POST',
             dataType: 'html',
             url: 'Menus/action',
             success: function (result) {
                 $('#ajaxResponse').html(result);
             },
             error: function (error) {
                 alert('Fail');
             }
         });
 });





这篇文章将返回一个部分视图,它将位于AjaxResponse div中。现在我遇到的问题是没有脚本可以在这个局部视图中使用。因为我在布局和脚本包之后渲染div的内容。



Ofcorse我可以将partialView设置为普通View来解决这个问题(渲染evrything),但我不想在这个div中有太多内容。



有没有人知道在ajax发布后从布局渲染这个脚本的方法?

已经尝试使用$(document).ready和$(action)。on(clickfunction())和一些技巧。但它没有用,因为脚本在这个div中不可用。



我在这个



This post will return a partial view which will be inside the AjaxResponse div. Now I have the issue that none of the scripts able to use inside this partial view. Because I render the content of the div after layout and script bundles.

Ofcorse I can set the partialView to a normal View to solve this problem(rendering evrything) but I don't want that much content inside this div.

Does anyone know a way to render this scripts from the layout after a ajax post?
already tryed to use $(document).ready and $("action").on("click" function()) and kind of tricks. But it didn't work because the scripts not usable inside this div.

I tryed also a click event on this



赞:




Like:

$('#ajaxResponse').on("click", function()) {
//my click event
}





这是有效的,但在双击动作中结束了。©br />


我希望你们中的某些人知道解决这个问题的正确方法!



This was working but ended up ofcorse in a double click action.

I hope someone of you guys know the right way to solve this!

推荐答案

( #action)。click(function(){
var id =
("#action").click(function () { var id =


('#ajaxResponse')。attr('data');
('#ajaxResponse').attr('data');


.ajax(
{
类型:'POST',
dataType:'html',
url:'菜单/操作',
成功:function(result){
.ajax( { type: 'POST', dataType: 'html', url: 'Menus/action', success: function (result) {


这篇关于MVC脚本无法在&lt; div&gt;内使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆