Dojo 在 MVC 局部视图中不起作用

Dojo doesn't work in MVC Partial View

我有局部视图:

<div id="AgreementBox@(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 (dom@(ViewData["UniqueId"]), checkbox@(ViewData["UniqueId"]), construct@(ViewData["UniqueId"]), ready@(ViewData["UniqueId"])) {
    ready@(ViewData["UniqueId"])(function () {
        agreecheckbox@(ViewData["UniqueId"]).placeAt(dom@(ViewData["UniqueId"]).byId("AgreementBox@(ViewData["UniqueId"])"), "first");
    });
    var agreecheckbox@(ViewData["UniqueId"]) = new checkbox@(ViewData["UniqueId"])(
        {
            id: "IAgreeToTermsOfUse@(ViewData["UniqueId"])",
            name: "iagreetotermsofuse@(ViewData["UniqueId"])",
            class: "i-agree-checkbox",
            checked: false
        });
});
</script>

我在每个表单下都使用这个视图(每个表单都有一个唯一的 id 我用作 ViewData["UniqueId"]):

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

当此视图每页出现一个时它起作用,但当它出现更多时,复选框不会出现在页面上。我没有收到任何错误,并且在 chrome 调试器中代码有效!

生成的输出:

<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> 

请帮我找出为什么会这样!

终于找到答案了!我仍然不知道为什么我以前的代码不起作用。我稍微修改了一下,现在可以完美运行了!

<div id="AgreementBox@(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 (dom@(ViewData["UniqueId"]), Create@(ViewData["UniqueId"])) {
    var checkbox@(ViewData["UniqueId"]) = Create@(ViewData["UniqueId"]).create("input", {
        type: "checkbox",
        id: "IAgreeToTermsOfUse@(ViewData["UniqueId"])",
        name: "iagreetotermsofuse@(ViewData["UniqueId"])",
        class: "i-agree-checkbox"
    });
    Create@(ViewData["UniqueId"]).place(checkbox@(ViewData["UniqueId"]), dom@(ViewData["UniqueId"]).byId("AgreementBox@(ViewData["UniqueId"])"), "first");
});
</script>

如果有人知道为什么我以前的代码不起作用,我会很乐意得到答案!我在这个问题上花了将近一个星期的时间,我仍然不知道为什么会这样!