asp.net-mvc

Ensuring IDisposable call on objects created in the controller and handed off to view

I have always known that all good programmers call Dispose on any object that implements IDisposable, case in point the ObjectContext class in EF. I am new to asp.net mvc so this may be a noob question but here goes... public ActionResult Index() { using (var db = new MyObjectContext()) { return Vie...

ASP.NET MVC: How can I serialized data from instance of classes generated by Linq2Sql?

Hello, I've learned to create multi-steps application from the Steve Sanderson's book (Pro ASP.Net MVC/APress p.477). Since then, I've adapted that Technique to many scenarios. Basically, it's about serialization/deserialization to keep data live between requests. But the only problem is I cannot use model generated by Linq2Sql becaus...

Why did they use this C# syntax to create a list of links in ASP.NET MVC 2?

I'm having hard time understanding the following C# code. This code was taken from Pro ASP.NET MVC 2 Framework by Steven Sanderson. The code esentially creates URLs based on a list of categories. Here's the code: Func<string, NavLink> makeLink = categoryName => new NavLink { Text = categoryName ?? "Home", ...

View Models in ASP.NET MVC that are similar to the Model classes

How do you handle situations where you have Model classes based on SQL tables, for instance when using Entity Framework to generate the Entities and data access for you but you would still like one or two properties to be different and/or excluded. I have no problem having separate View Model classes and Model classes but there's more a...

with mvc.net partial view, how do i access the model assigned to the template

I have another simple question for all you mvc gurus. I have a partial view with the following definition. <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IList<whoozit.Models.PictureModel>>" %> How do I access the data that has been assigned to the view? ...

How can I use some kind of IoC (?) to automatically register routes for my ASP.NET MVC controllers?

Currently I've found that it's most convenient to have a separate public static void RegisterRoutes(RouteCollection routes) method on each of my controllers. Then in Global.asax's RegisterRoutes, I call all of these methods. Of course, this is quickly getting out of hand. Every time I add a new controller, I have to go and update Regist...

ASP.NET MVC Subcontrollers

How can i create a sub-controller in ASP.NET MVC? i.e: In controller's directory i have a controller named Users.Fine.//GET:/Users/Index Inside controlles folder i have a subfolder named Groups,inside that subfolder i have a directory name Account,and inside Account i have a controller named Group. So,the URL should be: GET:/Groups/Ac...

What's wrong with these asp.net mvc routing rules?

I have defined a series of Routes in Global.asax.cs: public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute(null, "", // Only matches the empty URL (i.e. ~/) new { cont...

Injecting changes to model data

I have certain entities that have audit trail elements like LastUpdated and LastUpdatedBy. I am looking to determine the most appropriate way to effect an update of these fields to the current date and time and current user when a model is changed. The simplest implementation would be to affect this change in my controller before I upda...

jquery.form update target some of the time

I'm using jQuery.form plugin to .ajaxSubmit() between div's popping in and out of view (for logging and sometimes validation purposes). The user can navigate forward and backward. Some of the div's have full form data, in which case I would use the form's parent div as target:. However, the other div's contain text and navigation buttons...

can a forms action url contain querystring values?

can a forms action url contain querystring values? ...

ASP.NET MVC File Uploading

HI there, My model (partial) public class Document : HttpPostedFileBase { public string DocumentTitle { get; set; } public string DocumentType { get; set; } My action [AcceptVerbs(HttpVerbs.Post)] public ActionResult AddDocumentToVault(Document model) { foreach (string upload in Request.Fi...

Overload ASP.NET MVC Actions

How can I overload actions in ASP.NET MVC, but with support for GET QueryString? I tried to do something like this: public JsonResult Find(string q) { ... } public JsonResult Find(string q, bool isBlaBla) { ... } But whenever I access /controller/find?q=abc or /controller/find?q=abc&isBlaBla=false it throws anSystem.Reflectio...

Creating a Non-Blocking Process in an MVC 2 Application

I'm faced with setting up a system which will allow users to: Hit a button to initialize a "download & archive" command, which reads file lists via XML, pulls files over HTTP to a local directory, archives them, and stores them away for download. Get a progress bar/indicator telling them their "request is being processed" immediately a...

ASP.NET MVC AJAX call returning value to view from controller

During AJAX call is it possible to return ViewData, TempData or a session back to the view? does these variables are included in the cycle? please comment function submitForm(frm) { var tdata = $(frm).serialize(); $.ajax({ url: "/Organization/EditOrganizationMeta", data: tdata, succe...

ASP.NET MVC: Why do I get null instead of empty string when receiving POST request?

I used to receive empty string when there was no value: [HttpPost] public ActionResult Add(string text) { // text is "" when there's no value provided by user } But now I'm passing a model [HttpPost] public ActionResult Add(SomeModel Model) { // model.Text is null when there's no value provided by user } So I have to use th...

ASP.Net MVC Validation via DataAnnotations

I followed scottgu's blog here and tried to do data validation. Succeeded. However what I see is that if my field is a required field, i get an error as soon as i loose focus from my textbox. I want validation to happen only when I click submit. ...

How to go about reducing ASP.NET MVC application startup Memory Footprint?

I have an ASP.NET MVC application that also employs the typical NHibernate / Castle stack. On startup, the application's memory footprint sits around 190Mb and I wish to be able to run multiple isolated AppPools, each of which will serve a different domain. This is before really hitting anything serious in the database or putting anythin...

How can i route to different actions having same signature if i don't want to display action name in URL?

I am having one controller Test having following actions public ActionResult ABC (string parameter1, string parameter2) public ActionResult XYZ (string parameter1, string parameter2,string parameter3, string parameter4) i have added following html.routelinks <%= Html.RouteLink("ABC","ABC", new { parameter1 = 100, parameter2 = 200 } ...

Is there any big perfomance difference between RenderPartial and Partial?

Also RenderAction and Action. RenderXXX akaik write directly to response stream and XXX use additional string buffer. I don't really want doing benchmark my myself, so maybe someone already do it. ...