1

现在我正在显示项目表,他有一个Assing Link,当Assignwork单击Assign链接时,我将向他显示DropDown中的所有项目名称

型号代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Data.Entity;

namespace Gridview_BugTracker.Models
{
    public class BugTracker_DataHelper
    {

        public static List<BugTracker_DataHelper> GetList{get;set;}

          public int ProjectId { get; set; }
          public string projectName { get; set; }           
          public string Description { get; set; }
           public  string status { get; set; }
           public int EmployeId { get; set; }
           public string EmployeName { get; set; }

    }          

   }

控制器代码

  using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using System.Data;
    using Gridview_BugTracker.Models;
    using System.Data.SqlClient;
    using System.Data.Entity;

    namespace Gridview_BugTracker.Controllers
    {
        public class ProjectsController : Controller
        {
            //
            // GET: /Projects/
            /// <summary>
            ///
            /// </summary>
            /// <returns></returns>
            public ActionResult Index()
            {
                var bugedlist = GetList();
                return View(bugedlist);
            }
      /// <summary>
            /// The Bind data in Gridview
            /// </summary>
            /// <returns></returns>
            public List<BugTracker_DataHelper> GetList()
            {
                var modelList = new List<BugTracker_DataHelper>();
                using (SqlConnection conn = new SqlConnection(@"Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=BugTracker;Data Source=SSDEV6\SQLEXPRESS"))
                {
                    conn.Open();
                    SqlCommand dCmd = new SqlCommand("Select * from Projects", conn);
                    SqlDataAdapter da = new SqlDataAdapter(dCmd);
                    DataSet ds = new DataSet();
                    da.Fill(ds);
                    conn.Close();
                    for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
                    {
                        var model = new BugTracker_DataHelper();
                        model.ProjectId = Convert.ToInt16(ds.Tables[0].Rows[i]["ProjectId"]);
                        model.projectName = ds.Tables[0].Rows[i]["projectName"].ToString();
                        model.Description = ds.Tables[0].Rows[i]["Description"].ToString();
                        model.status = ds.Tables[0].Rows[i]["Status"].ToString();
                        modelList.Add(model);
                    }
                }
                return modelList;
            }
       /// <summary>
        /// Assign The Project Display
        /// </summary>
        /// <returns></returns>
        [AcceptVerbs(HttpVerbs.Get)]
        public ActionResult AssignProject()
        {
            var bugedlist = Assinedwrok();
            return View(bugedlist);

        }
           public List<BugTracker_DataHelper> Assinedwrok()
         {
            var modelList = new List<BugTracker_DataHelper>();
             using(
            SqlConnection assignedconn = new SqlConnection(@"Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=BugTracker;Data Source=SSDEV6\SQLEXPRESS"))
             {
                 {
                     assignedconn.Open();
                     SqlCommand Passnedcmd = new SqlCommand("select projectName from Projects", assignedconn);
                     SqlDataAdapter da = new SqlDataAdapter(Passnedcmd);
                     DataSet ds = new DataSet();
                     da.Fill(ds);

                     SqlDataReader adr = Passnedcmd.ExecuteReader();

                     for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
                     {
                         var model = new BugTracker_DataHelper();
                         model.projectName = ds.Tables[0].Rows[i]["projectName"].ToString();
                         modelList.Add(model);
                     }
                 }
                 return modelList;
             }
        }
        /// <summary>
        /// The Assigned The Work to Resources
        /// </summary>
        /// <returns></returns>
        public ActionResult AssignedWork()
        {
            return View();
        }
    }
}

索引查看代码

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<IEnumerable<Gridview_BugTracker.Models.BugTracker_DataHelper>>" %>

<!DOCTYPE html>

<html>
<head runat="server">
    <title>Index</title>
</head>
<body>
    <div>
    <h2>Index</h2>
    <p>
     <%: Html.ActionLink("Create New", "Create") %>
     <%:Html.ActionLink("Assign", "AssignProject")%>
      </p>
<table>
    <tr>         
        <th>
            ProjectName
        </th>

        <th>
           Status
        </th>


    </tr>

 <% foreach (var item in Model) { %> 

    <tr>          
        <td> 
            <%:Html.LabelForModel(item.projectName) %> 
        </td> 

        <td>
         <%:Html.LabelForModel(item.status) %>
        </td>

         <td>
            <%: Html.ActionLink("Edit", "Edit", new {id = item.ProjectId})%> |
            <%: Html.ActionLink("Details", "Details", new { id = item.ProjectId })%> |
            <%: Html.ActionLink("Delete", "Delete", new { id = item.ProjectId })%>
        </td>

        </tr>

       <%} %>
</table>
    </div>
</body>
</html>

关联视图代码

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<Gridview_BugTracker.Models.BugTracker_DataHelper>" %>

<!DOCTYPE html>

<html>
<head runat="server">
    <title>AssignProject</title>
</head>
<body>
    <div>
     <% using (Html.BeginForm()) 
     { %>      
    <%:Html.ValidationSummary(true)%>
     <fieldset>
        <legend>Projects</legend>
         <label for="ProjectName">ProjectName:</label>
         <%: Html.DropDownList("SelectItem",Model.projectName) %>

        </fieldset>
    <%} %>

    </div>
</body>
</html>

我收到错误

“/”应用程序中的服务器错误。

传入字典的模型项的类型为“System.Collections.Generic.List`1[Gridview_BugTracker.Models.BugTracker_DataHelper]”,但此字典需要“Gridview_BugTracker.Models.BugTracker_DataHelper”类型的模型项。


当我单击 assx 页面中的 Assingn 按钮时,它应该转到我的控制器中的 Assingn 方法所有都是列显示数据但没有得到 Deising 页面.....我在这里做错了什么............

4

0 回答 0