2017-09-20 2 views
-1

これは可能ですか? ビューにViewModelがバインドされています。フォームからのすべての入力値に対して、POST to Controllerアクションとしてフォームを送信すると、ViewModelのプロパティの1つとして設定されたJQueryのdatepicker入力から取得した日付を取得しますか?JQueryのdatepickerで選択した値をMVC ViewModelプロパティとしてController Actionに渡します

ViewModelには、このdatepickerフィールドのプロパティとしてvm.InputDateがあり、コントローラのアクションメソッドに別のパラメータを持つ代わりに、日付入力をViewModelのInputDateプロパティの値として設定してControllerに渡すことができますか?

ので、代わりに

public ActionResult Submit(ViewModel vm, DateTime inputDate) 

を有していると私は

public ActionResult Submit(ViewModel vm) 

を持っていると思いますが、vm.InputDateは私が行うことで考え出し

答えて

0

のjQueryのDatePickerの選択からinputDateに設定されています: を表示中:

@Html.EditorFor(model => model.InputDate, new { htmlAttributes = new { @id = "inputDatePicker", @class = "datepicker", @Name = "inputDate", @PlaceHolder = "mm/dd/yyyy" } }) 

$(function() { 
     $("#inputDatePicker").datepicker(
      { 
       showOtherMonths: true, 
       selectOtherMonths: true 
      }); 
    }); 

コントローラ内:

public ActionResult Replace(ViewModel vm) 
関連する問題