0

やあ; 2つのドロップダウンリストがあります。1つは顧客のddlで、もう1つは仕事です。選択プロセスの後、選択した値を存続させたい。でもできないんです。ボタンをクリックした後、ddlの選択したアイテムに選択した値を保持したい。(私は2つの方法を使用しました:dropdownlistとdropdownlistfor。)私のお気に入りの記事はhttp://stackoverflow.com/questions/6981698/how-to-keep-dropdownlist-selected-value-after-postbackとhttp://stackoverflowです。 .com / questions / 4950798 / how-to-post-the-selected-value-of-a-selectlist-to-the-controller-using-a-view-mo

ViewModel:


 public class MyViewModel
    {
        public IEnumerable<string> Columns { get; set; }
        public IEnumerable<dynamic> Values { get; set; }
        public bool HasNext { get; set; }
        public bool HasPrevious { get; set; }
        public IEnumerable<CustomerModel> Customers { get; set; }
        public IEnumerable<SelectListItem> Jobs { get; set; }
    }
  

コントローラー:


      public class JobController : Controller
      {
        public ActionResult Index(int? page)
        {
            var model = new MyViewModel();
            model.Customers = CustomerOperation.GetCustomers().Items;
            ViewData["Jobs"] = new SelectList(JobOperation.GetCustomersAssemblyList().Items, "scheduleId", "name", null);
            return View(model);
        }

意見:



 <table style="padding:25px; margin:10px 10px 10px 10px; width:800px" id="sample">
                <tr>
                <td>Customer Name: </td>
                <td>
               <%= Html.DropDownListFor(X=>X.Customers,new SelectList(Model.Customers,"Id","Name"),"** Please Select **", new { id = "ddlCustomers" })%>
               </td>
                <td>Job Name:</td>
                <td>
              <%= Html.DropDownList("Jobs", (IEnumerable<SelectListItem>)ViewData["Jobs"], "** Please Select **", new { id = "ddlJobs", disabled = "disabled" })%>
                </td>
                <td>
                 <input value="monitor" name="submitButton" type="submit" />
                </td>
                </tr>
                </table>

4

1 に答える 1

1

モデルは次のようになります

public class MyViewModel
{
    public IEnumerable<string> Columns { get; set; }
    public IEnumerable<dynamic> Values { get; set; }
    public bool HasNext { get; set; }
    public bool HasPrevious { get; set; }
    public IEnumerable<CustomerModel> Customers { get; set; }
    public IEnumerable<SelectListItem> Jobs { get; set; }

    public CustomerModel Customer {get; set;}
}

あなたの見解では、ドロップダウンを追加するコードは次のようになります

<%= Html.DropDownListFor(X=>X.Customer,Model.Customers) %>

お役に立てれば。

于 2012-07-05T11:19:28.113 に答える