Follow Fantora on Twitter
Fantora Word of Classified Ads and Community Forum
Welcome Guest Search | Active Topics | Members | Log In | Register

Linq query in MVC

Options
Aisha
Posted: Monday, December 12, 2011 3:17:00 PM
Rank: Advanced Member
Groups: Member

Joined: 12/12/2011
Posts: 294
Points: 394
Location: Lahore

Linq query in MVC

Hi,

I need to get the virtualuri value on the view. So these my model and view, I seem to miss something in this bit Url = q.ToString(); not sure what it is though, any advise would be appreciated.

On the View

I use this bit

<p>@Model.GetFriendlyUris(url)</p>

Model

public string GetFriendlyUris(string url)
{
using (TeachableEntities db = new TeachableEntities())
{
var q = (from r in db.site_urls where r.realuri == url select r.virtualuri);
Url = q.ToString();
}
return Url;
}
Fatima
Posted: Monday, December 12, 2011 3:21:32 PM
Rank: Advanced Member
Groups: Member

Joined: 12/12/2011
Posts: 175
Points: 234
Location: birmingham

Linq query in MVC

as might be expected, a linq query returns a query. you need to iterate it to execute the query. in general ToString of any object returns the class name. this is true for linq queries. if you look at the docs there are several helper methods. you might be interested in First() which return the first item of a colleciton, or Single() that checks that the collection has ona and only one item,

Url = q.Single().virtualuri;
Users browsing this topic
Guest

 Related
how to remove 404 error
Linq query in MVC
creating a profile in commerce server 2009 pragmatically
A little confusion on ICallbackEventHandler
using AdRotator control in ASP.Net
Could not load file or assembly 'XXX, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' ..
Commerce Server 2009 Starter Site step by step
nopCommerce ASP.NET/C# based opensource shopping cart Installation
MVC Application Structure
'System.Exception' was thrown
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Fantora Blog | Discount Shop UK | Discount Shop USA | Discount Shop Canada | Discount Boutique France | Discount Shop Deutschland | Discount Shop Italia | Descuento Shop España

Free Classified ads, Webmaster Forum & Technology Reviews | Fantora Free Classified Ads | Buy & Sell Electronics, Mobile phones & Accessories | fantora Forums Community | Buy & Sell DVD, Games and Consols | Free eBooks & Softwares | SEO & Affiliate Marketing Discussion | Programming Language Forum (.NET, ASP, PHP, SQL) | Free Classified Ads | General Stuff (Movies, Chat, Comics) | Free Online English Movies & Reviews | Free Online Hindi Movies & Reviews | Australia & New Zealand Immigration Forum | Europe immigration forum | Canada Immigration Forum | Ireland Immigration Forum | US Immigration Forum | United Kingdom Immigration Forum

Main Forum RSS : RSS

Powered by: YAF.NET
Copyright © AI Logica All rights reserved.
This page was generated in 0.165 seconds.