在视图中,模型显示了两个不同的值

时间:2019-05-02 14:45:16

标签: c# asp.net asp.net-mvc asp.net-mvc-5

这两个值不同。现在确定为什么会这样。任何人都知道为什么会这样吗?

     @Html.HiddenFor(m=>m.categoryCode, new { id="catCode", @Name="catCode"})           

    <input type="hidden" value="@Model.categoryCode"/>

以下是使用ajax请求的视图

@using (Ajax.BeginForm("UpdateShowroomCatClassMake", "Showroom", null, new AjaxOptions
                {
                    InsertionMode = InsertionMode.Replace,
                    HttpMethod = "GET",
                    UpdateTargetId = "ShowroomDiv",
                    OnSuccess = "CompleteUpdate",
                }, new { @class = "form-inline", method = "Get", id = "UpdateForm" }))
            {
                <div id="ShowroomDiv">
                    @Html.Partial("~/Views/Showroom/Filters/CatClassMakeFilter.cshtml", Model.catClassMakeFilterVM)

                </div>
                <div id="filterModal" class="modal fade" role="dialog">
        <div class="modal-dialog">

            <!-- Modal content-->
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                    <h4 class="modal-title">Filters</h4>
                </div>
                <div class="modal-body">
                    <div class="filters-modal-container">

                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                </div>
            </div>

        </div>
    </div>

CatClassMakeFilter.cshtml


@model Models.ShowroomVM.FiltersVM.CatClassMakeFilterVM


<div class="filters-container hidden-xs">
    <div class="filters-container-content">
        <div class="form-group padding-15">
            @Html.HiddenFor(m=>m.categoryCode, new { id="catCode", @Name="catCode"})
            <input type="hidden" value="@Model.categoryCode"/>
            <label>@Model.categoryLabel:</label>
            @Html.DropDownListFor(m =>m.categoryCode, new SelectList(Model.categories, "Value", "Text"), new { @class = "form-control margin-bottom-5", @onchange = "$('#UpdateForm').submit()" })
        </div>
        <div class="form-group padding-15">
            <label>@Model.classLabel:</label>
            @Html.DropDownListFor(m => m.classCode, Model.classes, new { @class = "form-control margin-bottom-5", @onchange = "$('#UpdateForm').submit()" })
        </div>
        <div class="form-group padding-15">
            <label>@Model.makeLabel:</label>
            @Html.DropDownListFor(m => m.make, Model.makes, new { @class = "form-control margin-bottom-5", @onchange = "$('#UpdateForm').submit()" })
        </div>
        <div class="form-group padding-15">
            <label class="">Sort By:</label>
            @Html.DropDownListFor(m => m.sortbyFilterVM.sortBy, Model.sortbyFilterVM.SortSelectionDDL, new { @class = "form-control margin-bottom-5", @onchange = "$('#UpdateForm').submit()" })
        </div>

        @Html.HiddenFor(m => m.showroomID)
        @Html.HiddenFor(m => m.page)
    </div>
</div>

我正在通过ajax请求更新值。返回的视图是CatClassMakeFilter.cshtml 两者的值都不同。

CatClassMakeFilterVM.cs


public class CatClassMakeFilterVM : BaseFilterVM
    {
        public CatClassMakeFilterVM()
        {
            categories = new List<SelectListItem>();
            classes = new List<SelectListItem>();
            makes = new List<SelectListItem>();
            sortbyFilterVM = new SortByFilterVM();
        }

        public string categoryLabel { get; set; }
        public string classLabel { get; set; }
        public string makeLabel { get; set; }

        public string categoryCode { get; set; }
        public List<SelectListItem> categories { get; set; }

        public string classCode { get; set; }
        public List<SelectListItem> classes { get; set; }

        public string make { get; set; }
        public List<SelectListItem> makes { get; set; }

        public SortByFilterVM sortbyFilterVM { get; set; }
    }

这是我在chrome开发工具中看到的值

enter image description here

0 个答案:

没有答案