2016-06-09 96 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> 

如果有人會發現爲什麼我以前的代碼不起作用,我會很高興得到答案!我在這個問題上花了近一個星期,我仍然不知道爲什麼會發生這種情況!