chinedu Nwankwo

chinedu Nwankwo

  • 1.8k
  • 94
  • 17.3k

ASP,NET MVC errors

Aug 18 2019 4:48 PM
Hello All ,
i have am try to search a table named BUI_TAB using a pinnumber , this table is linked to another table in my database called CUS_TAB , using CUS_ID which is a common field on both tables
I keep getting this error ......
Severity Code Description Project File Line Suppression State
Error CS0266 Cannot implicitly convert type 'System.Linq.IQueryable<<anonymous type: string NEW_TAR, double? ASS_QTY, string ASS_UNI, string BUI_TYP, string ZON_NAM_NEW, System.DateTime? ZON_COD_NEW, string WAT_CON_STA, string SUR_NAM, string OTH_NAM>>' to 'System.Collections.Generic.List<LiberiaWaterBillingApplication.ViewModels.Building_Customer>'. An explicit conversion exists (are you missing a cast?) LiberiaWaterBillingApplication C:\Users\chinedu\documents\visual studio 2017\Projects\LiberiaWaterBillingApplication\LiberiaWaterBillingApplication\Controllers\DataEntryController.cs 33 Active
////////////////.......................................this is my viewmodel................./////////////////////////////////////
public class Building_Customer
{
public string PIN_NUM { get; set; }
public string NEW_TAR { get; set; }
public string BUI_TYP { get; set; }
public string ASS_UNI { get; set; }
public string OCC_STA { get; set; }
public string SUR_NAM { get; set; }
public string OTH_NAM { get; set; }
public string ZON_COD_NEW { get; set; }
public string ZON_NAM_NEW { get; set; }
public string LOC_NAM { get; set; }
public string CUR_SNA { get; set; }
public string CUS_TEL { get; set; }
public string CUS_ADR { get; set; }
public string CUS_ADR2 { get; set; }
public string PTY_CON_STA { get; set; }
public string WAT_CON_STA { get; set; }
// public DbSet<BUI_TAB> BUI_TAB {get;set;}
// public DbSet<CUS_TAB> CUS_TAB {get;set;}
}
////////////////////........................this is my controller code....................//////////////////////////////////
public ActionResult searchpin1(string searchpin, LiberiaWaterBillingApplication.Models.BILLING_TABLE billmodel)
{
int searchpinint = Convert.ToInt16(searchpin);
List<Building_Customer> CustomerVMlist = new List<Building_Customer>();
CustomerVMlist = (from b in db1.BUI_TAB
join c in db1.CUS_TAB on b.CUS_ID equals c.CUS_ID
where b.PIN_NUM == searchpinint
select new
{
b.NEW_TAR,
b.ASS_QTY,
b.ASS_UNI,
b.BUI_TYP,
c.ZON_NAM_NEW,
c.ZON_COD_NEW,
c.WAT_CON_STA,
c.SUR_NAM,
c.OTH_NAM
});
//if (pin_details == null)
// {
//billmodel.= " You have not enetered a Pinnmumber";
//}
// else
//{ }
return View(CustomerVMlist);
}
//////////////......................this is my View..................//////////////////////////
@model IEnumerable<LiberiaWaterBillingApplication.ViewModels.Building_Customer>
@{
ViewBag.Title = "Newsearch";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Newsearch</h2>
<html>
<head>
<title>Login</title>
<style>
#login-div {
position: absolute;
left: 40%;
top: 40%;
border: 1px solid #ccc;
padding: 10px 10px;
}
.field-validation-error {
color: red;
}
</style>
</head>
<body>
<div id="login-div">
@using (Html.BeginForm("searchpin1", "DataEntry", FormMethod.Post))
{
<table>
<tr>
<td></td>
<td style="text-decoration:underline"></td>
</tr>
<tr>
<td><input type="text" name="pinsearch" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="submitbutton" value="Login" /><input type="reset" name="resetbutton" value="Reset" /></td>
<td> </td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</table>
}
</div>
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
</body>
</html>

Answers (1)