Is MVC Controller overkill for one page - asp.net

I've refactored my web application into one page (single page app). I'm just wanting some advice on whether serving up the one page index.cshtml with a controller is overkill (I'm not using any razor code that can't be substituted for normal html/js). Should I just change it to be a index.html page and just serve it as normal?
I'm sure it's only a minor thing, but want to know what the best practice is here.

No, it's not an overkill.
Just split your code into 3 parts: logics, HTTP processing, view.
It will be MVC even if all 3 parts are in 1 file.

Absolutely no need for MVC and all that BS.JS huge files when you're building a single page portfolio.
Just create a new HTML file.

Related

incorporate a html-css template as master page in asp.net- mvc 4

I am building a website, and want to do it using MVC 4. I dont want to use the custom asp.net template, and the asp.net templates available online do not meet my requirements. I have designed a html-css template and need to incorporate it into my project...(pretty much build the "contents folder" of the default templated mvc 4 project myself, if u know what i mean)...
I would really appreciate if someone points me to a tutorial or gives me a step-by-step account of how to do it.
You're pretty much looking for how to use Layouts and Sections with Razor. You can have as many as you'd like.
If I'm understanding correctly, you simply want to apply your template to _Layout.cshtml. This is similar in purpose to a MasterPage in ASP.NET web forms.
Here's a ScottGu blog on layouts and sections. (Just noticed that's the same link provided by #ErikPhilips)
To provide a simple explanation. _Layout.cshtml resides at Project\Views\Shared\_Layout.cshtml. By default it looks like a normal HTML file with a couple of unusual lines. The most important being #RenderBody(). When returning a ViewResult from an action (e.g. return View("MyView, myModel)), your view gets rendered by #RenderBody inside the layout. You can do what you like with _Layout.cshtml and if you're brave, you can also nest layouts.

Divide block of asp.net mvc code into different file parts

I have hundred lines of code asp.net in my view, It make me difficult to find what I need it. So do anyone have some idea to divide it into separate files? As I know, in php , have function include().
Take a look at ASP.NET MVC partial views. These let you break down your view into separate reusable components, similar to user controls in ASP.NET WebForms.

Organising asp.net website development process

Is there a standard practice to organize the process of developing a simple website. there is no use implementing MVC as there is no data base involved. It will be very useful in organizing the project and separating
the aspx files and master
page content(this can be very useful in implementing simple cms techniques)
user controls
scripts
styles
images
is there any industry standard or best practice for this.?
thanks in advance :)
Update: yes the way i have listed is convenient. but it would be great if i could separate server codes and files like master,aspx.. and the actual page content.
One more reason for not using MVC: I usually outsource the SEO process. Now an MVC application can be greek/latin for my SEO expert. :)
The final structure:
Project
Images
Scripts
Styles
Images
Weblets
Pagelets
aspx files..
the images, styles and scripts will contain only those that are common for the whole project. The weblets and pagelets are in the idea as follows...
Weblets should contain a collection of weblets. A weblet is folder containing a user control,it's styles,scripts,images etc.,
Pagelets should contain a collection of pagelets. A pagelet is a folder containing the content for the aspx page. If there is an aspx file named "aboutUs.aspx" then there is a corresponding pagelet named "aboutUs" which contains aboutUs.html,it's styles,scripts and images. the aspx page should only include them here.This can be very useful in configuring CMS.
If there can be betterments please do post..:)
No industry standards as such, but most developers I know would separate things out the way you did.
i.e. - different types of content in different directories.
That is right there is no such industry standard for this. But in my opinion i really like the Web Application Template from ASP.Net 4.0. It is more like MVC Template but it remain very useful in terms of scalability.
http://weblogs.asp.net/scottgu/archive/2009/08/26/starter-project-templates-vs-2010-and-net-4-0-series.aspx
ASP.Net MVC isn't just for database applications. In fact I would suggest it's easier to work with than webforms after the small learning curve. The concept of convention over configuration will help you with your question. There is a standard structure that MVC sets up for you that works great and anybody that opens your MVC code will be able to understand where everything is.

How do I remove ajaxpro *.ashx handlers from individual pages?

I working on a ASP.NET web project where Ajaxpro.2 is referenced, and it seems automatically to add a bunch of ashx handlers to the page output - ie, core.ashx, prototype.ashx.
The problem is, I only need these to be present on a few pages, not the entire site. In trying to optimize the page download size (particularly for static public pages), it would be really good if I could stop these handlers being magically included everywhere. Is this possible?
You have to call the AjaxPro.Utility.RegisterTypeForAjax only on the pages you want to have it, maybe a simple "if" statement would help.
Michael

Component controller in Spring-MVC

I am designing a web application that requires loading multiple components on a single page. (In terms of page layout is similar to Google reader) I like to keep these components separate from each other (for reasons such as reusability). For example, I have a left panel that let's user navigate among multiple feeds that he's subscribed to (user specific) and on the right side of that we show the contents of that feed, and maybe a right panel which shows some specific info about that specific feed.
My understanding of MVC and more specifically Spring-MVC is that each controller is in charge of the entire page. Here are 2 solutions that I have came up with after researching this a bit, and none of them sounds good to me.
Have a main controller that is mapped to that URL, and then load the other components from inside the jsp file. This is doable but doesn't sound like a good solution.
Using portlets.
I want to know what are the best practices. This sounds like a very common web design issue in MVC frameworks, how do people do it?
Spring MVC controller is usually "in charge" :-) of handling a particular request which does not necessarily mean that said request results in a monolithic page being presented to user.
Since you're talking about Google Reader-like functionality, perhaps you'll be using AJAX to load / navigate between different components on your page? If that's the case, you can easily map your 3 components to separate controllers (via separate URIs) plus have one "main" controller to initially load the entire page.
If that's not the case and your page is static, you can have your controller act as "router" of sorts by first instantiating your components and then directing commands / requests to an appropriate component as necessary. Each component would update its own part of the model after which your "main" controller would return the view to be rendered.
Can you use portlets for this? Sure. But if we're talking about a single page it might be a tad overkill.

Resources