c# - DbComparisonExpression requires arguments with comparable types -
I am new to using Linq and am trying to create a search that will search with chart number and Display the results will see the new action when the code is running, I get the error "DB Comrpigion Expression requires logic with rational type" I believe that there should be a search type string and some with the chart int int Is but me Not Keane problem how to fix would be greatly appreciate any help!
Controller: Model: See: New Controller Convert entry to number one
Public Performance Index (String SearchTerm = Faucet) {Var Model = DB. Patient. Where (r = & gt; search == faucet || r chart number. Ecloss (search)). Choose (R => New Newlist MODEL {chartNumber = R. Chartenumber, FirstName = R.Fst_Name, LastName = r.LastName,}); See Return (Model); }
public class NewListModel {public int chartnumber {get; Set; } Public string first name {receives; Set; } Public String LastName {get; Set; }}
@Emelumerable & lt; Project.Models.NewListModel & gt; @ {ViewBag.Title = "Home Page"; } & Lt; Form method = "get" & gt; & Lt; Input type = "search" name = "search term" /> & Lt; Input type = "submit" value = "search by chart number" / & gt; & Lt; / Form & gt; @wunch (Miscellaneous items in the model) {& lt; Div & gt; & Lt; h4 & gt; @ item.ChartNumber & lt; / H4 & gt; & Lt; / Div & gt; & Lt; Div & gt; @ item.FirstName & lt; / Div & gt; & Lt; Div & gt; @ Item.LastName & lt; / Div & gt; }
Public Action Result Index (string searchTerm = null) {int chartNo; If (searchTerm == faucet || Int32.TryParse (searchTerm, out of chartNo) {var model = db.Patient. Where (R = & gt; Search == empty; r.ChartNumber == chartNo). Select (r = & gt; New Newlostodel {ChartNumber = R. Chartenumber, FirstName = R.Fst_Name, LastName = R. ListName,}); See Return (Model); } else {// enter invalid number}}
int :
int chartNo = 0; If (searchTerm == faucet || Int32.TryParse (searchTerm, out of chartNo) {var model = db.Patient. Where (r = & gt; searchorm == zero; r chart number == not charts). Choose (.. .); Return ...; } else {// invalid number entered}
Comments
Post a Comment