开发者

web ui controls and ASP.NET MVC

Why will not fill View page of this controller method

public ActionResult Person()
    {
        testEntities6 testPersons = new testEntities6();
        IQueryable<person> persons;

        DropDownLst.Items.Clear();
        DropDownLst.Items.Add("proba");

        persons = from i in testPersons.person
                  select i;
        return View(persons);
    }

and include namespaces:

  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.Mvc;
  using System.Web.Mvc.Ajax;
  using MvcKVteam.Models;
  using System.Web.UI;
  using Sy开发者_开发技巧stem.Web.UI.WebControls;
  using System.Web.UI.WebControls.WebParts;
  using System.Web.UI.HtmlControls;

In view page I put this code:

  <asp:DropDownList ID="DropDownLst" runat="server">
  </asp:DropDownList>


I don't think you can use server controls in MVC. You should be using HTML Helpers instead.

Based on your existing code:

<%= Html.DropDownList("DropDownLst", Model.AsEnumerable()) %>

But I would recommend using a View Model instead of just passing an IQueryable to the View. I also recommend you pick up an MVC book. Professional ASP.NET MVC 1.0 is really good, but doesn't cover the 2.0 release.

Rich

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜