Hướng dẫn assign model value to javascript variable mvc - gán giá trị mô hình cho biến javascript mvc

Tôi đang cố gắng gán một giá trị từ một mô hình cho một biến JavaScript. Nhưng tôi phải kiểm tra một điều kiện trước khi làm như vậy.

Thông thường, tôi có thể gán các giá trị bằng cách sử dụng câu lệnh này trong tập lệnh: var quantity = '@Model.Quantity'. Nó hoạt động, nhưng tôi không biết làm thế nào để làm điều này bên trong một vòng lặp nếu-


    @if [Model.Count == 0]
    {
        var quantity = 0;
    }
    else
    {
        var quantity = '@Model.Quantity';
    }

Nhưng câu lệnh bên trong vòng lặp sẽ được hiển thị là C#. Vậy làm thế nào để tôi đạt được điều này? Tôi phải lưu trữ số lượng vào một biến JavaScript bên trong vòng if.

Cảm ơn :]

}

Tôi đang sử dụng Net Core và tạo một trang dao cạo. & NBSP; Tôi muốn sử dụng một biến từ lớp mô hình trong JavaScript để tôi có thể thực hiện yêu cầu với AJAX để lấy dữ liệu liên quan.

& nbsp; & nbsp; & nbsp; @Html.actionLink ["Quay lại danh sách", "index"]
For testing purposes, I added Id2 to check if something is wrong with the steps before this.

public string Id { get; set; }
public string Id2 { get; set; }

public async Task OnGetAsync[string id]{
 Id = id;
 Id2 = "02222";
}

Có lẽ tôi đang cố gắng đặt giá trị sai vị trí. & NBSP; Có lẽ tôi nên cố gắng sử dụng cú pháp dao cạo để gọi mã Knockout/ JavaScript một cái gì đó như sau:

@Html.dropdownlistfor [model => model.residencystatecd, newselectlist [enumerere.empty [], "ResidencyStatecd", "cư trú"],

"Vui lòng chọn trạng thái", mới {id = "states"}]03043 and 02222] , I get 1170 and 1571. Where do these numbers come from? I just defined these variables now and one of them is hardcoded. If I hardcode the variable inside the js to be "02222" then it will show the correct variable, but not if I get it from the model. 
I also tried using this:

@page "{id:int?}"
...
var id2 = @ViewContext.RouteData.Values["id"];

Nhưng tôi sẽ nhận được 1170 thay vì dự kiến ​​& nbsp; 03043. Các số tôi nhận được là nhất quán vì vậy nếu ID là & nbsp; 03043 thì tôi luôn nhận được 1170.03043. The numbers I get are consistent so if the id is 03043 then I always get 1170 in return.

Bất kỳ ý tưởng? Cảm ơn
Thanks

Xin chào, nếu bạn muốn sử dụng giá trị mô hình trong JavaScript, thì bạn cần truy cập giá trị mô hình như thế này
If you want to use model value in javascript,then you need to access model value like this

var modelJsValue = '@model.id'; [mã dao cạo] hoặc ''

Bây giờ modeljsvalue của bạn sẽ có giá trị của ID thuộc về mô hình của bạn.

Giải pháp cập nhật:


        jQuery[document].ready[function [] {
            // initiate layout and plugins
            App.init[];
            var modelJSValue = '@Model.Id';
alert[modelJSValue]; //Confirm and see what we get at this point.
            Calendar.init[modelJSValue]; //Pass modelJSvalue to your script
}];

Lưu ý: Đảm bảo bạn cũng đọc giá trị tham số trong tệp JS của bạn. Hy vọng điều này sẽ giúp bạn một chút.
Hope this helps you a bit.

Trân trọng, RK
RK

Tôi đã thấy câu hỏi này được hỏi bởi các lập trình viên MVC3/Knockout ít kinh nghiệm hơn như tôi nhưng tôi đã bắt gặp bất cứ ai trả lời câu hỏi. & NBSP; Câu hỏi có thể nằm ngoài cơ sở nhưng thật tuyệt khi biết mọi thứ nên được xử lý như thế nào. & NBSP; Nếu bạn không làm việc với MVC3 thì bạn có thể không hiểu câu hỏi này bắt nguồn từ đâu.

Trong MVC3, tôi có một mô hình chế độ xem phức tạp mà tôi chuyển từ bộ điều khiển của mình sang chế độ xem. & NBSP; Khi tạo chế độ xem, tôi chỉ định dao cạo [CSHTML] là công cụ xem, chế độ xem được gõ mạnh và lớp mô hình. & NBSP; Điều này đặt một câu lệnh của @Model myApp.ViewModels.MyComplexModelClass trong chế độ xem.

Trong HTML của tôi tạo thành một ánh xạ điển hình đến trường mô hình chế độ xem MVC3 sau đó sẽ giống như sau đây. & NBSP;

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp;

Lưu ý rằng tôi đã tìm thấy cú pháp trên trong một ví dụ khác và tôi đã không cố gắng kết nối nó theo logic loại trực tiếp /Ajax của mình.@Html.EditorFor[model => model.Country]

Tôi đã thấy câu hỏi này được hỏi bởi các lập trình viên MVC3/Knockout ít kinh nghiệm hơn như tôi nhưng tôi đã bắt gặp bất cứ ai trả lời câu hỏi. & NBSP; Câu hỏi có thể nằm ngoài cơ sở nhưng thật tuyệt khi biết mọi thứ nên được xử lý như thế nào. & NBSP; Nếu bạn không làm việc với MVC3 thì bạn có thể không hiểu câu hỏi này bắt nguồn từ đâu.@Html.ValidationMessageFor[model => model.Country]

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp;

Lưu ý rằng tôi đã tìm thấy cú pháp trên trong một ví dụ khác và tôi đã không cố gắng kết nối nó theo logic loại trực tiếp /Ajax của mình.

Tôi đã thấy câu hỏi này được hỏi bởi các lập trình viên MVC3/Knockout ít kinh nghiệm hơn như tôi nhưng tôi đã bắt gặp bất cứ ai trả lời câu hỏi. & NBSP; Câu hỏi có thể nằm ngoài cơ sở nhưng thật tuyệt khi biết mọi thứ nên được xử lý như thế nào. & NBSP; Nếu bạn không làm việc với MVC3 thì bạn có thể không hiểu câu hỏi này bắt nguồn từ đâu.

Trong MVC3, tôi có một mô hình chế độ xem phức tạp mà tôi chuyển từ bộ điều khiển của mình sang chế độ xem. & NBSP; Khi tạo chế độ xem, tôi chỉ định dao cạo [CSHTML] là công cụ xem, chế độ xem được gõ mạnh và lớp mô hình. & NBSP; Điều này đặt một câu lệnh của @Model myApp.ViewModels.MyComplexModelClass trong chế độ xem.

Trong HTML của tôi tạo thành một ánh xạ điển hình đến trường mô hình chế độ xem MVC3 sau đó sẽ giống như sau đây. & NBSP;

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; @Html.editorfor [model => model.country]this.muncipalityCd.subscribe[function [municipalityCd] {" is where I am trying to set the MVC3 view model variable.   Also, at the end of the sample there is another possible approach that I have listed.

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; @Html.validationMessageFor [model => model.Country]

Thông thường khi mọi thứ được điền vào biểu mẫu HTML của tôi, tôi chỉ cần gọi điện tử gửi và dao cạo truyền mô hình xem MVC3 của tôi trở lại bộ điều khiển nơi tôi có thể xử lý các phản hồi của người dùng.

Mọi thứ đều tuyệt vời cho đến khi tôi muốn thực hiện Tra cứu Knockout/JavaScript cho một danh sách chọn. Để làm điều này, tôi tạo một mô hình chế độ xem JavaScript, liên kết các biến thích hợp và gọi hành động tra cứu trên bộ điều khiển. & NBSP; Tôi có thể thấy giá trị của mình trở lại trong trình gỡ lỗi nhưng tôi không thể gán nó cho biến mô hình MVC3 View thích hợp. & NBSP;KiltR.ViewModels.Residency

Trong các ví dụ, tôi đã thấy những người khác tiếp cận vấn đề này bằng cách chuyển đổi toàn bộ mô hình chế độ xem MVC3 thành mô hình chế độ xem JavaScript, liên kết thủ công các trường và sau đó chuyển mô hình chế độ xem JavaScript/JSON trở lại bộ điều khiển khi biểu mẫu hoàn tất. & NBSP; Vấn đề với điều này là nó có vẻ như rất nhiều công việc thủ công, nó có thể không hoạt động với mô hình xem MVC3 phức tạp của tôi, các chú thích dữ liệu của tôi sẽ ngừng hoạt động [@html.validationMessagefor [model => model.country]], v.v.

Một biến JavaScript từ một cuộc gọi loại trực tiếp có thể được ánh xạ hoặc gán cho biến mô hình xem MVC3, tức là, biến mô hình MVC3 Xem = Giá trị loại bỏ JavaScript? & NBSP; Knockout có thể được triển khai với các mô hình MVC3 View không?"MVC Knockout Example";

Mã mẫu dưới đây là từ một dự án tôi đã tập hợp lại để cô lập vấn đề này trong ứng dụng của tôi. & nbsp; Lưu ý rằng trong phần mã bắt đầu bằng "this.muncipalitycd.subscribe [function & nbsp; [đô thị] {" là nơi tôi đang cố gắng đặt biến mô hình xem MVC3. Một cách tiếp cận có thể khác mà tôi đã liệt kê.

@*Index*@

Index

*@

Cảm ơn bạn cho bất kỳ hướng dẫn nào bạn có thể cung cấp trong khi tiếp cận kịch bản này & nbsp;script src="@Url.Content["~/Scripts/jquery.validate.min.js"]" type="text/javascript">

Cảm ơn bạn cho bất kỳ hướng dẫn nào bạn có thể cung cấp trong khi tiếp cận kịch bản này & nbsp;script src="@Url.Content["~/Scripts/jquery.validate.unobtrusive.min.js"]" type="text/javascript">

Cảm ơn bạn cho bất kỳ hướng dẫn nào bạn có thể cung cấp trong khi tiếp cận kịch bản này & nbsp;script type="text/html" id="noInfoTemplate">

Vật mẫu

Cảm ơn bạn cho bất kỳ hướng dẫn nào bạn có thể cung cấp trong khi tiếp cận kịch bản này & nbsp;script>

Cảm ơn bạn cho bất kỳ hướng dẫn nào bạn có thể cung cấp trong khi tiếp cận kịch bản này & nbsp;script type='text/javascript'>

Vật mẫufunction [] {

@Model Kiltr.ViewModels.Residency@Html.Raw[ new System.Web.Script.Serialization.JavaScriptSerializer[].Serialize[Model]];

@{var residencyItems = function [] {

& nbsp; & nbsp; & nbsp; Viewbag.title = "Ví dụ về loại bỏ MVC";this.residencyStateCd = ko.observable[];

}this.countyCd = ko.observable[];

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; var ResidencyItems = function [] {this.muncipalityCd = ko.observable[];

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; Không có thông tin có sẵn [chọn tiểu bang, quận và sau đó là đô thị]this.schoolDistictCd = ko.observable[];

& nbsp; & nbsp; & nbsp; $ [document] .reed [function [] {this.states = ko.observableArray[];

// & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; var initialData = @html.raw [New System.web.script.serialization.javascriptserializer []. serialize [mô hình]];this.counties = ko.observableArray[];

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; this.this.municipalities = ko.observableArray[];

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; this.schooldistricts = ko.ObServableArray [];this.schoolDistricts = ko.observableArray[];

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; this.residencyserverModel = ko.ObServable [initalData];this.residencyServerModel = ko.observable[initialData];

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; var chọnStateCd = không xác định;var selectedStateCd = undefined;

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; var chọnCountycd = không xác định;var selectedCountyCd = undefined;

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; var selectMunIdioncd = không xác định;var selectedMunicipalityCd = undefined;

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; var chọnSchooldistrictcd = không xác định;var selectedSchoolDistrictCd = undefined;

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; // Bất cứ khi nào nhà nước thay đổi, hãy đặt lại lựa chọn quận// Whenever the state changes, reset the county selection

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; this.ResidencyStateCd.SubScribe [function [statecd] {this.residencyStateCd.subscribe[function [stateCd] {

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; selectStateCd = statecd;

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; initalData.ResidencyStateCd = Statecd;

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; this.countycd [không xác định];this.countyCd[undefined];

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; this.counties [không xác định];this.counties[undefined];

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; if [statecd! = null] {if [stateCd != null] {

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; $ .ajax [{

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; URL: '@url.action ["getCounties", "mvcknockout"]','@Url.Action[ "GetCounties", "MVCKnockout"]',

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; Dữ liệu: {statecd: statecd},

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; Loại: 'Nhận','GET',

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; Thành công: function [dữ liệu] {function [data] {

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; ResidencyViewModel.Counties [dữ liệu];

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; }

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; }];

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; }

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; } .bind [cái này]];this]];

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; // Bất cứ khi nào quận thay đổi, hãy đặt lại lựa chọn đô thị// Whenever the county changes, reset the municipality selection

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; this.countycd.subscribthis.countyCd.subscribe[function [countyCd] {

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; đã chọnCountycd = Countycd;

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; initalData.CountyCD = CountyCD;

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; this.muncipalitycd [không xác định];this.muncipalityCd[undefined];

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; this.Munities [không xác định];this.municipalities[undefined];

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; if [Countycd! = null] {if [countyCd != null] {

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; $ .ajax [{

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; URL: '@url.action ["getCounties", "mvcknockout"]','@Url.Action[ "GetMunicipalities", "MVCKnockout"]',

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; Dữ liệu: {statecd: statecd},

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; Loại: 'Nhận','GET',

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; Thành công: function [dữ liệu] {function [data] {

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; ResidencyViewModel.Munity [Dữ liệu];

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; }

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; }];

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; }

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; } .bind [cái này]];this]];

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; // Bất cứ khi nào đô thị thay đổi, hãy đặt lại lựa chọn khu học chánh// Whenever the municipality changes, reset the school district selection

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; this.muncipalitycd.subscribe [functionthis.muncipalityCd.subscribe[function [municipalityCd] {

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; đã chọnMunIdioncd = đô thị;

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; initalData.MunIdionalcd = đô thị;

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; this.schooldistictcd [không xác định];this.schoolDistictCd[undefined];

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; this.schooldistricts [không xác định];this.schoolDistricts[undefined];

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; if [đô thị! = null] {if [municipalityCd != null] {

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; $ .ajax [{

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; URL: '@url.action ["getSchooldistricts", "mvcknockout"]','@Url.Action[ "GetSchoolDistricts", "MVCKnockout"]',

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; Dữ liệu: {statecd: selectStatecd, CountyCD: chọn ChịCountycd, đô thị: đô thị},

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; Loại: 'Nhận','GET',

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; Thành công: function [dữ liệu] {function [data] {

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; if [data] {if[data] {

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; ResidencyViewModel.Schooldistricts [dữ liệu];

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; // Đây là nơi tôi đang cố gắng đặt mô hình xem MVC3 của mình, tức là thay thế các trường JS var bằng các trường mô hình xem MVC// This is where I am attempting to set my MVC3 view model i.e., replace the JS var fields with the MVC view model fields

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; var tempcd = data [0] .schooldistrictcd; //Những công việc này...var tempCd = data[0].SchoolDistrictCd; //This works...

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; var tempdescr = data [0] .schooldistrictdescr; //Những công việc này...var tempDescr = data[0].SchoolDistrictDescr; //This works...

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; @["Cư trú.schooldistrictcd"] = tempcd; & nbsp; // Điều này không hoạt động ....@["Residency.SchoolDistrictCd"] = tempCd;  //This does not work....

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; }

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; }

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; }];

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; }

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; } .bind [cái này]];this]];

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; // Bất cứ khi nào đô thị thay đổi, hãy đặt lại lựa chọn khu học chánh

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; var ResidencyViewModel = new ResidencyItems [];var residencyViewModel = new residencyItems[];

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; KO.ApplyBindings [ResidencyViewModel];

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; // Tải các trạng thái//Load the states

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; $ .ajax [{

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; URL: '@url.action ["getResidencyStates", "mvcknockout"]','@Url.Action[ "GetResidencyStates", "MVCKnockout" ]',

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; Loại: 'Nhận','GET',

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; Thành công: function [dữ liệu] {function [data] {

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; ResidencyViewModel.states [Dữ liệu];

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; }

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; }];

& nbsp; & nbsp; & nbsp; }];

@Using [html.beginform []] {using [Html.BeginForm[]] {

& nbsp; & nbsp; & nbsp; @Html.validationsummary [đúng]@Html.ValidationSummary[true]

& nbsp; & nbsp; & nbsp;

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; Cư trúResidency

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp;

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; @Html.labelfor [model => model.country]@Html.LabelFor[model => model.Country]

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp;

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp;

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; @Html.labelfor [model => model.country]@Html.EditorFor[model => model.Country]

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; @Html.editorfor [model => model.country]@Html.ValidationMessageFor[model => model.Country]

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp;

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp;

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; @Html.labelfor [model => model.country]*@Html.LabelFor[m => m.ResidencyStateCd]

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp;

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp;

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; @Html.labelfor [model => model.country] model.country]data-bind='

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp;@html.validationMessageFor [model => model.country]

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; *@Html.labelfor [M => M.Residencystatecd]

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp;

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; Data-Bind = '

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; Tùy chọn: Trạng thái,

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; @Html.labelfor [model => model.country]

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp;

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; @Html.labelfor [model => model.country]

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; @Html.editorfor [model => model.country]*@Html.LabelFor[m => m.CountyCd]

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; @Html.labelfor [model => model.country]

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; @Html.labelfor [model => model.country]

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; @Html.editorfor [model => model.country] model.country]data-bind='

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; *@Html.labelfor [M => M.Residencystatecd]

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp;

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; Tùy chọnStext: "CountyDescr",

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; Tùy chọncaption: "[Vui lòng chọn một quận]",

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; Giá trị: Countycd,

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp;

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp;

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp;

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp;

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp;

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp;

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; *@Html.labelfor [M => M.Muncipalescd]*@Html.LabelFor[m => m.MuncipalityCd]

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp;

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp;

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp;

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp;

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp;

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; *@Html.labelfor [M => M.Muncipalescd]

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; Data-Bind = '

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; Tùy chọn: Countycd []? Thành phố: Null,

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp;

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp;

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp;

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp;

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp;

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; *@Html.labelfor [M => M.Schooldistrictcd]*@Html.LabelFor[m => m.SchoolDistrictCd]

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp;

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp;

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; M.Schooldistrictcd]data-bind='

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; Data-Bind = '

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; Tùy chọn: Muncipalitycd []? schooldistricts: null,@*ScSclDistCd", *@

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; Tùy chọnValue: "Schooldistrictcd", @ *scscldistcd ", * @

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; Tùy chọnStext: "Schooldistrictdescr",

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; Tùy chọncaption: "[Vui lòng chọn một khu học chánh]",

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; Giá trị: Schooldistictcd,

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp;

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp;

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp;

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp;

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; *@Html.labelfor [M => M.Schooldistrictcd]

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp;

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; *@Html.labelfor [M => M.Schooldistrictcd]

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; Data-Bind = '

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; Tùy chọn: Muncipalitycd []? schooldistricts: null,

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; Tùy chọnValue: "Schooldistrictcd", @ *scscldistcd ", * @div>

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; Tùy chọnStext: "Schooldistrictdescr",@Html.ActionLink["Back to List", "Index"]

Có lẽ tôi đang cố gắng đặt giá trị sai vị trí. & NBSP; Có lẽ tôi nên cố gắng sử dụng cú pháp dao cạo để gọi mã Knockout/ JavaScript một cái gì đó như sau:div>

@Html.dropdownlistfor [model => model.residencystatecd, newselectlist [enumerere.empty [], "ResidencyStatecd", "cư trú"],

"Vui lòng chọn trạng thái", mới {id = "states"}]Html.DropDownListFor[model => model.ResidencyStateCd, new SelectList[Enumerable.Empty[], "ResidencyStateCd", "Residency"],

Thay vì điều này từ mẫu trên:, new { id = "states" }]

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp;

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp;

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; Data-Bind = '

Lưu ý rằng tôi đã tìm thấy cú pháp trên trong một ví dụ khác và tôi đã không cố gắng kết nối nó theo logic loại trực tiếp /Ajax của mình.

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; Data-Bind = '

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp;

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; Data-Bind = '

Bài Viết Liên Quan

Chủ Đề