我是Javascript的新手我有一个MVC视图(AddUser.cshtml),同样也会在编辑操作上调用,这个AddUser.cshtml有JS函数,在$(document).ready(function(){中调用 BindEditData(); }。我试图只在编辑模式下调用它,但不知何故这样做不成功。它也参与了ADD行动。请看我的代码,请建议....
<script type="text/javascript">
$(document).ready(function ()
var data = {
GlobalVar: [
]}
if ($("#UserID").val()>0) {
SetAddressDataInEditMode();
}
function SetAddressDataInEditMode()
{
var myArray = [];
@foreach(var d in Model.MyModel)
{
@:InsertAddressData("@d.AddressID", "@d.AddressLabel", "@d.Line1", "@d.Line2", "@d.CountryID", "@d.CountryStateID", "@d.StateCityID", "@d.Zip", "@d.Status");
}
function InsertAddressData
(SAddressID, SAddressLabel, SLine1, SLine2, SCountryID,
SCountryStateID, SStateCityID, SZip, SStatus)
{
data.GlobalVar.push({
AddressID: SAddressID,
AddressLabel: SAddressLabel,
Line1: SLine1,
Line2: SLine2,
CountryID: SCountryID,
CountryStateID: SCountryStateID,
StateCityID: SStateCityID,
Zip: SZip,
Status: SStatus
});
}
//Call Display address
DisplayAddressDetails();
}