如何修复数据类型中的“详细信息页面”错误

时间:2019-09-03 11:00:38

标签: c# asp.net-mvc asp.net-mvc-5

我正在建立一个新的页面,其中包含element的详细信息,并希望在页面中支持nvarchar值。我需要在哪里更改代码?

我的控制器

 public ActionResult Details(string id)
        {
            try
            {
                if (string.IsNullOrEmpty(id))
                {
                    return RedirectToAction("TimeSheet", "AllTimeSheet");
                }
             MainTimeSheetView objMT = new MainTimeSheetView();
                objMT.ListofVacationsDayoffs = _ITimeSheet.GetVacationsbyTimeSheetMasterID(Convert.ToInt32(id));


                objMT.TimeSheetMasterID = Convert.ToInt32(id);
                return View(objMT);
            }
            catch (Exception)
            {
                throw;
            }
        }

我的课

public class GetVacations
    {
        public string Vacations { get; set; }
    }

我的程序查询清单

 public List<GetVacations> GetVacationsbyTimeSheetMasterID(int TimeSheetMasterID)
        {
            using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["TimesheetDBEntities"].ToString()))
            {
                con.Open();
                try
                {
                    var param = new DynamicParameters();
                    param.Add("@TimeSheetMasterID", TimeSheetMasterID);
                    var result = con.Query<GetVacations>("Usp_GetVacationsbyTimeSheetMasterID", param, null, true, 0, System.Data.CommandType.StoredProcedure).ToList();
                    if (result.Count > 0)
                    {
                        return result;
                    }
                    else
                    {
                        return new List<GetVacations>();
                    }
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }

我尝试从数据库显示nvarchar值的html,只有当我将值转换为int时,它才起作用。

@model WebApp.Models.Model

      foreach (var item in Model.ListofVacationsDayoffs)
   {
      <td><b>@Html.DisplayFor(modelItem => item.Vacations)</b></td>

   }

还有MianTimeSheetView的公共类

  public class MainTimeSheetView
    {

        public List<GetVacations> ListofVacationsDayoffs { get; set; }

    }

我的程序是

SELECT     

      CASE WHEN Hours = 1 THEN  0
      WHEN Hours = 2 THEN 0
      WHEN Hours = 3 THEN 0
      WHEN Hours = 4 THEN 0
      WHEN Hours = 8 THEN 8
      ELSE 0
      END
        AS Vacations
  FROM [TimeSheetDetails]    t  
  where TimeSheetMasterID =@TimeSheetMasterID 

0 个答案:

没有答案