Raju Fodse

Raju Fodse

  • 1.5k
  • 244
  • 31.5k

List view in MVC with Date Parameter

Sep 10 2018 12:10 AM
I am new in MVC. I want list view to generate by passing Date Parameter in controller; But I got error please help me solve the problem. my controller code is
 
  1. LPDBContext DB = new LPDBContext();  
  2.            var items = db.Processes.Where(x =>x.PRDate.ToShortDateString().Equals(08 / 09 / 2018)).ToList();  
  3.              
  4.            return View(items); 
My List View code is
  1. @model IEnumerable<EasyApp.Models.Process>    
  2.     
  3. @{    
  4.     ViewBag.Title = "ExportP3List";    
  5.     Layout = "~/Views/Shared/_Layout.cshtml";    
  6. }    
  7. <div class="EasyViewDiv table-responsive">    
  8.     <h2>Cutting</h2>    
  9.     
  10.      <table style="font-size:smaller;" class="table table-bordered">    
  11.         <tr>    
  12.             <th>    
  13.                 Production Date    
  14.             </th>    
  15.             <th>    
  16.               In-Out Time    
  17.             </th>    
  18.             <th>    
  19.                Employer    
  20.             </th>    
  21.             <th>    
  22.                 Operator Name    
  23.             </th>    
  24.             <th>    
  25.                WO No    
  26.             </th>    
  27.             <th>    
  28.                OD    
  29.             </th>    
  30.             <th>    
  31.                Thk    
  32.             </th>    
  33.             <th>    
  34.                Specification    
  35.             </th>    
  36.             <th>    
  37.                 Pipe No    
  38.             </th>    
  39.             <th>    
  40.                Length    
  41.             </th>    
  42.             <th>    
  43.                 MT    
  44.             </th>    
  45.             <th>    
  46.                Actual Meter    
  47.             </th>    
  48.             <th>    
  49.                Time Taken    
  50.             </th>    
  51.             <th>    
  52.                 Speed    
  53.             </th>    
  54.     
  55.                 
  56.         </tr>    
  57.     
  58.         @foreach (var item in Model)    
  59.         {    
  60.             <tr>    
  61.                 <td>    
  62.                     @Html.DisplayFor(modelItem => item.PRDate)    
  63.                 </td>    
  64.                 <td>    
  65.                     @Html.DisplayFor(modelItem => item.Atten.INTIME) TO @Html.DisplayFor(modelItem => item.Atten.OUTIME)    
  66.                 </td>    
  67.                 <td>    
  68.                     @Html.DisplayFor(modelItem => item.Atten.Emp.CompanyID)    
  69.                 </td>    
  70.                 <td>    
  71.                     @Html.DisplayFor(modelItem => item.Atten.Emp.EmpName)    
  72.                 </td>    
  73.                 <td>    
  74.                    @Html.DisplayFor(modelItem => item.PipeAl.Order.WONO)    
  75.                 </td>    
  76.                 <td>    
  77.                     @Html.DisplayFor(modelItem => item.PipeAl.Order.DIA)    
  78.                 </td>    
  79.                 <td>    
  80.                     @Html.DisplayFor(modelItem => item.PipeAl.Order.THK)    
  81.                 </td>    
  82.                 <td>    
  83.                     @Html.DisplayFor(modelItem => item.PipeAl.Order.PISPEC)    
  84.                 </td>    
  85.                 <td>    
  86.                     @Html.DisplayFor(modelItem => item.PIPENO)    
  87.                 </td>    
  88.                 <td>    
  89.                     @Html.DisplayFor(modelItem => item.PipeAl.LENGTH)    
  90.                 </td>    
  91.                 <td>    
  92.                     @Html.DisplayFor(modelItem => item.PipeAl.MT)    
  93.                 </td>    
  94.                 <td>    
  95.                     @Html.DisplayFor(modelItem => item.ActualMeter)    
  96.                 </td>    
  97.                 <td>    
  98.                     @Html.DisplayFor(modelItem => item.CuttingTime)    
  99.                 </td>    
  100.                 <td>    
  101.                     @Html.DisplayFor(modelItem => item.CuttingSpeed)    
  102.                 </td>    
  103.                            </tr>    
  104.         }    
  105.     
  106.     </table>    
  107. </div>  
 
I got following error
 
LINQ to Entities does not recognize the method 'System.String ToShortDateString()' method, and this method cannot be translated into a store expression.  

Answers (6)