2016-06-09 78 views
0

我有局部视图:道场不MVC局部视图工作

<div id="[email protected](ViewData["UniqueId"])" class="agreement-box"> 
    <span> 
     I read agreement 
    </span> 
    <a> 
     terms of usage 
    </a> 
</div> 

<script> 
    require([ 
    'dojo/dom', 
    "dijit/form/CheckBox", 
    "dojo/dom-construct", 
    "dojo/ready"], 
function ([email protected](ViewData["UniqueId"]), [email protected](ViewData["UniqueId"]), [email protected](ViewData["UniqueId"]), [email protected](ViewData["UniqueId"])) { 
    [email protected](ViewData["UniqueId"])(function() { 
     [email protected](ViewData["UniqueId"]).placeAt([email protected](ViewData["UniqueId"]).byId("[email protected](ViewData["UniqueId"])"), "first"); 
    }); 
    var [email protected](ViewData["UniqueId"]) = new [email protected](ViewData["UniqueId"])(
     { 
      id: "[email protected](ViewData["UniqueId"])", 
      name: "[email protected](ViewData["UniqueId"])", 
      class: "i-agree-checkbox", 
      checked: false 
     }); 
}); 
</script> 

我利用一切形式下,这种观点(每个表单有一个唯一的ID女巫我作为ViewData的使用[“唯一ID”]) :

@Html.Partial("../MyPartialView", new ViewDataDictionary { { "UniqueId", "Order" } }) 

当这个视图出现在每个页面上时,它会起作用,但是当它看起来更多时,这个复选框就不会出现在页面上。我没有得到任何错误,并在铬调试器的代码工作!

生成的输出:

<div id="AgreementBoxContact" class="agreement-box"> 
    <span> 
     I read agreement 
    </span> 
    <a> 
     terms of usage 
    </a> 
</div> 
<script> 
    require([ 
    'dojo/dom', 
    "dijit/form/CheckBox", 
    "dojo/dom-construct", 
    "dojo/ready"], 
function (domContact, checkboxContact, constructContact, readyContact) { 
    readyContact(function() { 
     agreecheckboxContact.placeAt(domContact.byId("AgreementBoxContact"), "first"); 
    }); 
    var agreecheckboxContact = new checkboxContact(
     { 
      id: "IAgreeToTermsOfUseContact", 
      name: "iagreetotermsofuseContact", 
      class: "i-agree-checkbox", 
      checked: false 
     }); 
}); 
</script> 
// 
//on the same html page 
// 
<div id="AgreementBoxOrder" class="agreement-box"> 
    <span> 
     I read agreement 
    </span> 
    <a> 
     terms of usage 
    </a> 
</div> 
<script> 
    require([ 
    'dojo/dom', 
    "dijit/form/CheckBox", 
    "dojo/dom-construct", 
    "dojo/ready"], 
function (domOrder, checkboxOrder, constructOrder, readyOrder) { 
    readyOrder(function() { 
     agreecheckboxOrder.placeAt(domOrder.byId("AgreementBoxOrder"), "first"); 
    }); 
    var agreecheckboxOrder = new checkboxOrder(
     { 
      id: "IAgreeToTermsOfUseOrder", 
      name: "iagreetotermsofuseOrder", 
      class: "i-agree-checkbox", 
      checked: false 
     }); 
}); 
</script> 

请帮我看看,为什么它的发生!

+0

尝试用'''dojo/domReady!'代替''dojo/ready''' – ben

+0

我试过了,但是得到了同样的结果。 – levkaster

+0

不确定要了解这是如何工作的。它是多个复选框下的一种形式或一个复选框跨多个表单? – ben

回答

0

最后我找到了答案!我仍然不知道为什么我以前的代码不起作用。我改变了一点,现在它完美的工作!

<div id="[email protected](ViewData["UniqueId"])" class="agreement-box"> 
    <span> 
     I read agreement 
    </span> 
    <a> 
     terms of usage 
    </a> 
</div> 
} 
<script type='text/javascript'> 
    require([ 
    'dojo/dom', 
    "dojo/dom-construct", 
    "dojo/domReady!"], 
function ([email protected](ViewData["UniqueId"]), [email protected](ViewData["UniqueId"])) { 
    var [email protected](ViewData["UniqueId"]) = [email protected](ViewData["UniqueId"]).create("input", { 
     type: "checkbox", 
     id: "[email protected](ViewData["UniqueId"])", 
     name: "[email protected](ViewData["UniqueId"])", 
     class: "i-agree-checkbox" 
    }); 
    [email protected](ViewData["UniqueId"]).place([email protected](ViewData["UniqueId"]), [email protected](ViewData["UniqueId"]).byId("[email protected](ViewData["UniqueId"])"), "first"); 
}); 
</script> 

如果有人会发现为什么我以前的代码不起作用,我会很高兴得到答案!我在这个问题上花了近一个星期,我仍然不知道为什么会发生这种情况!