cshtml and ascx in one MVC3 app - asp.net-mvc-3

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.

Related

MVC 5 Razor view displays Linq errors but page renders correctly

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...

Design View for ASP.NET MVC3 Views

Is there a Design View in ASP.NET MVC3 ?
There is no 'Design' view in MVC, like there is in Forms. However your views are just HTML so you can use any HTML editor, although they will not be able to interpret the Razor syntax.
What most people do is make changes to the HTML, save (you don't have to recompile,) and refresh your browser. Google Chrome has a very help full tool built in (Firebug or something like it.) Just right click on the page and select Inspect Element. This will come in very handy.
Also one thing to think about since you're new to MVC is that you can easily use most any css themes that you can find online to make the site look very different out of the box.

MVC 3 Razor - Use script references in Layout page from Partial View

I used some jquery in my partial view and realised that I need to have the script reference put in the partial view Again in order for the jquery to works.
I wonder is there any method which I can "call" all the script references in the Layout page so I dont need to duplicate it in the Partial View??
I tried to search for related information and tried to use #section to store the script references, but it seems cant work.
Hope can get some guide here... Appreciate it...
You can put all your script references in a Partial View of its own, and then call #Html.Partial("ScriptReferences") from both the Layout page and the other Partial View that needs the script references.
I normally include/reference all the scripts in my layout view. Although some are not needed on all pages.
The partial views, do not have to worry about a script not available. And it also saves time during development.
The overhead of having all scripts available is minimal. Specially if you merge all .js files in one big minimized script (Chirpy can do that for you). Modern browsers will know it's the same script and not download and parse them over and over.
Script references in Layout page are automatically shared with partial views. You might encounter issues if the Home page (which loads layout) URL and the partial view URLs are not relative ... Use relative URLs to load the partial views and the sharing of script file references and global namespaces would work ...
I found another option that turned out to make my life a lot better:
http://kazimanzurrashid.com/posts/asp-dot-net-mvc3-razor-script-loading-tips

ASP.NET MVC 3 : Design choice for view engine

I'm going to create a website with lots of business logic, connected to a background data model. For these reasons I chose ASP.NET MVC3 as development platform.
Unfortunately, I left web programming at the time of the old ASP and JSP and lately I worked with windows applications and C#.
Now I'm wondering which is the best(easiest, fastest, most reliable, most compatible with browsers) technique to create user views?
I explored a little Razor, but it is unclear for me, is it a so good choice? Is it supported by forums or still too fresh?
I'm very tempted of using webcontrols since I'm now addicted to them. Would this be a good choice? Can I use webcontrols just in aspx or in razor as well?
What about Ajax controls? Would it be a better choice?
Thanks!
Yes, Razor is a good choice. See here for a pretty good summary.
As Robert mentioned, "controls" go against the MVC pattern and will not even work in Razor. You want html helpers for small bits of markup (for example, to render a text box) and partial views for more complicated things (like a shopping cart widget)
Use of AJAX depends on the UI needs of your application. Initially it would be simpler to start without AJAX. Also, some clients might have JavaScript disabled and then AJAX would not work.
"web controls" are not appropriate for MVC at all - they go against the MVC pattern. Instead, look into "partial views" for creating common bits of UI that get reused across multiple pages

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