cannot convert from 'int' to 'System.Linq.IQueryable<string>' in MVC4

Posted by Mandlaa under ASP.NET MVC on 10/7/2013 | Points: 10 | Views : 3152 | Status : [Member] | Replies : 5
cannot convert from 'int' to 'System.Linq.IQueryable<string>' in MVC4


public ActionResult Sss(string styleName,int? tagno)
{
var styles = from s in db.ProductsHondaofConyers select s;
if (!String.IsNullOrEmpty(styleName))
{
styles = styles.Where(c => c.StockNo.Contains(styleName));
}
else
{
styles = styles.Where(r => r.TagNo.Contains(styleName));
}
return View(styles);
}

this is my code for this




Responses

Posted by: Bandi on: 10/7/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Make sure that you have TagNo, StockNo as Strings

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Mandlaa, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Mandlaa on: 10/7/2013 [Member] Starter | Points: 25

Up
0
Down
Actually what i am doing here is,

I want search functionality in MVC4 with database
In my database
Tagno-----int

StockNo----Varchar in my database

I want to search data from database using Tagno or StokeNo

VIEW:

@using (Html.BeginForm("Sss","Home",FormMethod.Get))
{
<p>
StockNo:@Html.TextBox("styleName")<br />
<input type="submit" value="Search StockNo" />
</p>

<p>
Tagno:@Html.TextBox("tagno")<br />
<input type="submit" value="Search Tagno" />
</p>
}
</p>

Controller:(Home)

public ActionResult Sss(string styleName,int? tagno)
{
var styles = from s in db.ProductsHondaofConyers select s;
if (!String.IsNullOrEmpty(styleName))
{
styles = styles.Where(c => c.StockNo.Contains(styleName));
}
else
{
styles = styles.Where(r => r.TagNo.Contains(tagno));
}
return View(styles);
}

Mandlaa, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 10/7/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
try this in ELSE Block

styles = styles.Where(r => SqlFunctions.StringConvert((double)r.TagNo).Contains(tagno));


Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Mandlaa, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Mandlaa on: 10/7/2013 [Member] Starter | Points: 25

Up
0
Down
I am using LinqToSql,
SqlFunctions----this is entity model

Mandlaa, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 10/7/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Are you searching for multiple tag Numbers ?
If NOT, try this...
styles = styles.Where(r => r.TagNo == tagno);


Reference:
http://stackoverflow.com/questions/558054/how-to-know-if-a-field-is-numeric-in-linq-to-sql?lq=1

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Mandlaa, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response