MVC 5 Razor view displays Linq errors but page renders correctly - linq

I frequently get errors such as displayed in the picture below when using Linq in a Razor view. I have obviously added the #using System.Linq include on the top of the page (although it will strangely work without it), but still get the errors no matter what i try.
Is there any way to prevent these errors from appearing? I know i shouldn't be using too much code inside a view, perhaps the best solution would be to build the list in the code, use it here and stop worrying about editor syntax errors?
Razor Linq Error

This kind of problems is often in some way related to the config files. Have you seen this answer?
The type 'IEnumerable<>' is defined in an assembly that is not referenced
You can also try to create a test project and see if everything works as expected there and if it does, compare the web config files for possible differences... Note that there are two of those in each mvc project...

Related

VS2013 - Error on a view causes browser to display symbols

Using vs2013 to create an MVC5.2 web app. I'm actually rebuilding an old app using the new mvc framework, so this works fine in vs2010 and MVC3.
In this app, whenever i have something that would trigger an error on the page (usually in a razor syntax, like
#{Html.RenderPartial("mypartial", mymodel);}
instead of getting a compilation error yellow screen when viewing it in a browser, i get a page of symbols:
I created an new web app and it doesn't do it in there, it displays the error as expected. I'm assuming this is caused by something i retrieved/updated via NuGet, but if anyone had any idea of where to start looking, it'd be appreciated.
EDIT: further experimenting seems to indicate that this only happens within areas. If i have a razor syntax error in the root controller, i get a yellowscreen. same error in a view that is in an area results in the symbol display below.
Figured out my problem- I had added a EnableCompression action filter that i was using in MVC3 to my MVC5 controllers. This was causing the weird display- taking it out completely cleared up the problem.
Apparently now gzip compression is handled either in IIS or in the web.config file, I've seen reports of both. At any rate, I no longer have to deal with it in the application itself.

Telerik problems with IntelliSense and Templates

I am working on the project where I use Telerik MVC controls in order to show some NumericTextBoxes and other controls. I have two problems that are maybe related.
1/ IntelliSense works fine in Views/Shared and in some Views. But in some it doesn´t work. The code is absolutely similar without specific blocks of code. I try to add all Telerik namespaces to Web.Config in Views folder, but it doesn´t work. Just in Views/Shared is IntelliSense working.
2/ I would like to use [SourceCodeFile] attribute in my Controller in order to using NumericTextBoxes templates. But VS says "Unknown attribute" and "Resolve" is not in context menu. I was trying to add all Telerik namespaces but it still doesn´t work.
Some suggestions?

Dev Express MVC Extensions with Razor - Controls Show as Lists

Any DevExpress control I use, just renders a list. I’ve tried all 3 possible syntaxes (listed on the site below) and every time, the control I want to use (TreeView, NavBar, etc.) just renders as a bulleted list. Any ideas why? I’ve checked Google and the DevExpress support center, but I can’t find any issues like this.
DevExpress with razor guide: http://documentation.devexpress.com/#AspNet/CustomDocument9944
I just put this code on my index page to test that DevExpress is working:
#{Html.DevExpress().NavBar(settings => {
settings.Name = "myNavBar";
settings.Groups.Add("Group1").Items.Add("Item1-1");
settings.Groups.Add("Group2").Items.Add("Item2-1");
settings.Groups.FindByText("Group2").Expanded = false;
}).Render();}
When it reaches the page, it just shows a bulleted list:
Group1
Item1-1
Group2
Any ideas what's causing this?
The project I was working on was being rendered inside another project. I just needed to get rid of my project's layout and add using statements to the cshtml pages:
#using DevExpress.Web.Mvc.UI;
#using DevExpress.Web.Mvc;
The only problem I still have, is the scriptlet code gets highlighted red (but it builds/works fine and has intellisense).
It seems that any required DevExpress' entry is not registered within the MasterPage (_Layout.cshtml) / Web.config http://help.devexpress.com/#AspNet/CustomDocument8163. I suggest that you use specially designed Visual Studio Project Templates http://help.devexpress.com/#AspNet/CustomDocument9145 to avoid missing any required DevExpress' entry.

cshtml and ascx in one MVC3 app

Is there something wrong to use both types of views (cshtml and ascx) in single MVC3 app? We use old-school Master with server-side form. So all views are basically .aspx. But sometimes in case of partial views it is handy to use cshtml instead of ascx.
Is it ok? Or there are some troubles in future with that way?
No answers so far. Trying to answer by myself.
It's OK in general. All works fine. BUT! If you can use only one type (cshtml OR ascx), you have to use only one to make your project more unified.

mvc html.serialize to store model in view

Can anyone tell me what happened to the Html.Serialize function mentioned in the url below.
It's not recognized when I try and use it in a MVC2 web app within Visual Studio 2010.
http://weblogs.asp.net/shijuvarghese/archive/2010/03/06/persisting-model-state-in-asp-net-mvc-using-html-serialize.aspx
EDIT - I'm using visual studio 2010 which comes with mvc2 'built in' when i try and use Html.serialize on a view or partial view it's not appearing in intellisense. Am i missing a reference or something?
It hasn't gone anywhere. It is right there, wherever you are able to use the html extensions. Eg, Views, PartialViews.
For example:
<%= Html.Serialize("wizardData", Model)%>
Are you trying to use it in a controller? To use it as shown in the article you quote, you need to use it in a view.
You see, we really don't know because you haven't given us any detail to work with. Show us some code, and we will move your earth. Well, try to anyway.
I see you are new, so when asking questions, try to give as much detail as possible. You can edit your post, just mark out what you have done. The more context we get, the more we can help.
I found out why! I was having similar problems too.
You need to download ASP.NET 2 Futures and use the DLLs provided there instead of the usual Mvc DLL.
It is implemented in SerializationExtensions class.
It's in the MVCFutures assembly and not part of the out the box MVC framework. You will need to add the package via nuget or manual download and then add a using/imports statement to Microsoft.Web.Mvc before you can use it in your view.

Resources