Post 将只读值更新为 MVC 中的 Action

Post Updated readonly values to Action in MVC

我有以下 formmethod=get.

@using (Html.BeginForm("Search", "Home", FormMethod.Get, htmlAttributes: new { @class = "main-search", id = "frmsearch", role = "form" })) {
<div class="row">
  <div class="col-md-3 col-sm-3">
    <div class="form-group">
      <label for="type">Property Type</label>
      @Html.ListBoxFor(m => m.searchModel.CategoriesId, Model.searchModel.Categories, htmlAttributes: new { id = "type", multiple = "multiple", @class = "animate", data_transition_parent = ".dropdown-menu", title = "All" })
    </div>
    <!-- /.form-group -->
  </div>

  <div class="col-md-3 col-sm-3">
    <div class="form-group">
      <label for="location">Location</label>
      @Html.DropDownListFor(m => m.searchModel.LocationID, Model.searchModel.Locations, htmlAttributes: new { id = "location", multiple = "multiple", @class = "animate", data_transition_parent = ".dropdown-menu", title = "All" })
    </div>
    <!-- /.form-group -->
  </div>
  <div class="col-md-3 col-sm-3">
    <div class="form-group">
      <label>Status</label>
      @Html.DropDownListFor(m => m.searchModel.StatusID, Model.searchModel.Status, htmlAttributes: new { id = "status", multiple = "multiple", @class = "animate", data_transition_parent = ".dropdown-menu", title = "All" })
    </div>
    <!-- /.form-group -->
  </div>
  <div class="col-md-2 col-sm-3">
    <div class="form-group">
      <label>Price</label>
      <div class="ui-slider" id="price-slider-category" data-value-min="@Model.searchModel.MinPrice" data-value-max="@Model.searchModel.MaxPrice" data-value-type="price" data-currency="&#8377;" data-currency-placement="before">
        <div class="values clearfix">
          @Html.TextBoxFor(m => m.searchModel.MinPrice, htmlAttributes: new { id = "value-min", @class = "value-min", name = "value-min[]", @readonly = "readonly", style = "padding:0px" }) 
          @Html.TextBoxFor(m => m.searchModel.MaxPrice, htmlAttributes: new { id = "value-max", @class = "value-max", name = "value-max[]", @readonly = "readonly", style = "padding:0px" })
        </div>
        <div class="element"></div>
      </div>
    </div>
    <!-- /.form-group -->
  </div>
  <div class="col-md-1 col-sm-3">
    <div class="form-group">
      <label></label>
      <button type="submit" style="color:white" id="searchSubmit" class="btn btn-block blue waves-effect">
        <i class="fa fa-search"> </i>
      </button>
    </div>
    <!-- /.form-group -->
  </div>
  <!--/.col-md-6-->
</div>
<!--/.row-->
}

我有这个 JS 到 post form 值到 AJAX

$(document).on('click', '#searchSubmit', function (e) {
        var _form = $(this).closest('form');
        var _url = _form.attr('action');
        var formData = _form.serialize();
        var request = $.get(_url, formData);
        request.complete(function (response) {

        })
})

这是我的 model

public class SearchFilters
{
    public SearchFilters()
    {
         MinPrice = 10000;
         MaxPrice=8000000;
    }
    public IEnumerable<SelectListItem> Categories { get; set; }
    public int[] CategoriesId { get; set; }

    public IEnumerable<SelectListItem> Locations { get; set; }
    public int[] LocationID { get; set; }

    public IEnumerable<SelectListItem> Status { get; set; }
    public int[] StatusID { get; set; }

    public int MinPrice { get; set; }
    public int MaxPrice { get; set; }
}

这是我处理搜索请求的controller方法。

[HttpGet]
public ActionResult Search([Bind(Prefix = "searchModel")]SearchFilters smodel)
{
     ProjectsViewModel model = new ProjectsViewModel();
     //search db and fill model
     return PartialView("_PropertyDetails", model);
}

使用 noUiSlider 插件对最小值和最大值进行 UI 渲染,因此输入为 readonly 但通过 noUiSliderupdate 选项更新.但是,只要在服务器中收到模型,它就会作为默认值分配给模型变量,即使在更新之后也是如此。在 DOM 中检查时,这些值不会更新,但会反映在 UI 中。是的,这是因为 textboxreadonly 属性 但是 有没有其他方法可以 post 这些类型的只读 属性 值situations? 以下是 UI 的外观以及收到时的 DOMmodel 值的一些屏幕截图。

UI

DOM

型号

更新

我可以在 URL 中看到 posted 值作为 ...searchModel.MinPrice=₹2%2C189%2C090.00&searchModel.MaxPrice=₹5%2C772%2C480.00 但不是在模型中。不知道如何开始..

, 格式化使 MinPriceMaxPrice 成为字符串。因此,这些不会绑定到 int 属性。只需删除格式并将它们发送到 GET,然后它们将绑定到 int 属性。