Domanda

Objective: Provide the user with a way to add an additional date picker using something like a partial postback

Issue: I am new to MVC 4 and not exactly sure how to employ a partial postback. How do I make the code below work so that if the date is selected in the first drop down, a new one will be added without a full postback? Thank you in advance for any comments and suggestions.

The code is as follows:

View

 @using Model
 @model Form

 @section scripts{
      <script src="@Url.Content("~/Scripts/date.js")" type="text/javascript"></script>
      <script src="@Url.Content("~/Scripts/jquery.datePicker.js")" type="text/javascript"></script>
      <script src="@Url.Content("~/Scripts/datePicker.js")" type="text/javascript"></script>
 }

 <div class="editor-label">
            @Html.Label("SomeDate", "Some Date,")
            @DatePicker.Picker(this.Html, Model.FilterModel.SomeDate, "Report", "SomeDate", true,  true)
 </div>
 @if((Model.FilterModel.SomeDate2 != null))
 <div class="editor-label">
            @Html.Label("SomeDate2", "Some Date 2,")
            @DatePicker.Picker(this.Html, Model.FilterModel.SomeDate2, "Report", "SomeDate2", true,  true)
 </div>
È stato utile?

Soluzione

Your question is not very descriptive so i will answer in two ways if that ok

**I would do the following for a "just two dates" scenario **

Hide the second date (display:none) i would then use Js and act on the date picker changed event to unhide the second date.

**I would do the following for a "Multiple dates" scenario **

use @Ajax.BeginForm() around the first date (Editable date). Use Js to fire the submit on the form when the date has changed.

The Submit will return a Partial View showing:

  1. List of previous dates (readonly maybe)
  2. And a new editable date at the bottom.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top