Click here to Skip to main content
15,881,413 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I have a table in database as Users and i have a view form as Kartable want use user list in this view page as dropdown list but don't work

What I have tried:

Model File:
C#
namespace ResidentCertificate.Models
{
    public class Users_
    {
          public Int32 UserID { get; set; }
          public string userName { get; set; }
          public Int32 userAccessID { get; set; }
          public Int32 organizational_positionID { get; set; }
          public string loginTime { get; set; }
          public string logofTime { get; set; }
          public string computerName { get; set; }
          public string computerIP { get; set; }

    }

part of Data access layer file :
C#
using ResidentCertificate.Interfaces;
using ResidentCertificate.Models;

namespace ResidentCertificate.DataAccess
{
    public class Users_DataAccessLayer : IUsers_
    {
        public string connectionString = globalsetting.connectionstring;

       public IEnumerable<users_> GetAllUsers_()
        {
            try
            {
                List<users_> lstusers_ = new List<users_>();

                using (SqlConnection con = new SqlConnection(connectionString))
                {
                    SqlCommand cmd = new SqlCommand("spGetAllUsers_", con);
                    cmd.CommandType = CommandType.StoredProcedure;

                    con.Open();
                    SqlDataReader rdr = cmd.ExecuteReader();

                    while (rdr.Read())
                    {
                        Users_ users_ = new Users_();

                        
                         users_.UserID = Convert.ToInt32(rdr["UserID"]);
                         users_.userName=rdr["userName"].ToString();
                         users_.userAccessID = Convert.ToInt32(rdr["userAccessID"]);
                         users_.organizational_positionID = Convert.ToInt32(rdr["organizational_positionID"]);
                         users_.loginTime=rdr["loginTime"].ToString();
                         users_.logofTime=rdr["logofTime"].ToString();
                         users_.computerName=rdr["computerName"].ToString();
                         users_.computerIP=rdr["computerIP"].ToString();


                        lstusers_.Add(users_);
                    }
                    con.Close();
                }
                return lstusers_;
            }
            catch
            {
                throw;
            }
        }

Kartabl Controller File:
C#
using ResidentCertificate.Models;
using ResidentCertificate.Interfaces;
using ResidentCertificate.DataAccess;

namespace ResidentCertificate.Controllers
{
    public class KartablController : Controller
    {
        // GET: KartablController
        DataAccess.Users_DataAccessLayer userslist = new Users_DataAccessLayer();
        public ActionResult Index()
        {
            IEnumerable<models.users_> Model = userslist.GetAllUsers_();
            
            return View();
        }

Kartabl view file:
Razor
@model IEnumerable<residentcertificate.models.users_>
...
Posted
Updated 15-Feb-21 6:01am
v3
Comments
Ali Jafarinezhad 14-Feb-21 7:28am    
Richard Deeming 15-Feb-21 12:03pm    
"Don't work" is not a description of a problem that anyone can help you with.

Click the green "Improve question" link and update your question to include a complete description of the problem. Include the full details of any errors, and remember to indicate which line of code they relate to.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900