asp.net-mvc

How to unit test a custom actionresult

I'm trying to unit test a custom action result. I recently watched Jimmy Bogard's excellent MvcConf video ("put your controllers on a diet") http://www.viddler.com/explore/mvcconf/videos/1/ and have started to try and implement some custom action results. I've managed that without a problem, the ActionResult works fine at runtime but I'm...

Posting an array in mvc form

I am looking for solutions / suggestions on posting an string[]. My Model (Program), defines the target property (Levels) as a string. I can achieve this by just using FormCollection, but would prefer to pass that string[] right into the model from the post. Here are snippets: ProgramConotroller/Create // // POST: /Program/Create [Http...

create a WIKI like "diff" between two strings

i am generating a report showing the different between fields before and after. I have it working but some of the fields are pretty long and the changes are quite subtle. I want some visualization to highlight what has changed. Similar to what you see in: Stackoverflow if you look at question edits One of the text file diff tools wh...

Accessing custom principal within a custom ActionFilterAttribute

I am working on an ASP.NET MVC application. I have implemented custom membership provider, principal and identity. In the custom provider I replace the HttpContext.Current.User in the ValidateUser() method as follows: public sealed class CustomMembershipProvider : MembershipProvider { ... public override bool ValidateUs...

How to approach unit testing in a large project

We have a project that is starting to get large, and we need to start applying Unit Tests as we start to refactor. What is the best way to apply unit tests to a project that already exists? I'm (somewhat) used to doing it from the ground up, where I write the tests in conjunction with the first lines of code onward. I'm not sure how to s...

When should functionality be made available in its own Controller?

I am working on a web application that has to present charts on different pages. Each page corresponds to a Controller, and each Controller that needs a chart has an interface to a ChartService. The service requests a chart from a third party vendor. It then returns an image wrapped up in some HTML with JavaScript as a string directly in...

Why can't I reference JavaScript files in my View?

My JS works when I reference it in the MasterPage, and it works when I reference it in a Partial View (.ascx), but not when I reference from the View (.aspx). Any ideas why? ...

How to construct HttpPostedFileBase?

I have to write a Unit test for this method but I am unable to construct HttpPostedFileBase... When I run the method from the browser, it works well but I really need an autoamted unit test for that. So my question is: how do I construct HttpPosterFileBase in order to pass a file to HttpPostedFileBase. Thanks. public ActionResult ...

StructureMap StackOverFlow??? Very Confused

I am building a mvc app using structuremap.. I have quite a few places where I use ObjectFactory.GetInstance(). my app was working fine until I added a couple more functions, now all it does when I start up my app in VWD2010 express is stall and give me a StackOverflowException when I debug. and most of the exceptions are with ObjectFact...

.NET 4 function : Function argument question

I'm following a tutorial on MVC on the .NET 4 framework. The tutorial created a function like this... using System.Web; using System.Web.Mvc; namespace vohministries.Helpers { public static class HtmlHelpers { public static string Truncate(this HtmlHelper helper, string input, int length) { if (inpu...

Is this code business logic or presentation logic?

This code exists in a View: if (Model.Group.IsPremium && null != Model.Group.ContactInfo) { Html.RenderPartial("ContactInfo", Model.Group.ContactInfo); } at first glance, it's presentation logic and so it's ok. But it's not sitting well with me. The thing is, it's a business requirement to display con...

Nerd dinner error on Ajax call to Register action method

I'm new to MVC and I'm implementing the Nerd Dinner MVC sample app in MS MVC2. I'm on step 10, "Ajax enabling RSVPs accepts". I've added the new RSVP controller and added the Register action method like so: public class RSVPController : Controller { DinnerRepository dinnerRepository = new DinnerRepository(); // // AJAX: /Di...

Is a HTML helper a place for Business Logic?

I asked this question earlier about business logic and presentation logic, and it got me thinking.. I think it's easier to spot questionable practice when looking at code in a View because I'm automatically suspicious when I see it. Usually it's ok because it's presentation logic, but I always tend to look closer. But I don't look as cl...

Sending collection of items in ASP.NET MVC

Hello all! I've got two classes in my MVC project Order and Product. Because Product can be ordered many times and Order can have many products I've got third entity which is OrderedProduct. It joins those two entities in many-to-many relation. Now what I'm trying to do is to let user to make an order by putting products from the drop...

ASP.NET MVC forces an AJAX request be redirected to the login page when the FormsLogin session is no longer active

I have some AJAX calls that render PartialViewResults via the jQuery.AJAX method. This works great, I get my views rendered exactly the way I want. The problem arises when I leave the page up for a while and the Forms auth session expires. When I click an action that performs an AJAX request, it shows the login page in my div. I want ...

How to display tabpanel based upon permissions?

Hello All i am doing project in ASP .Net MVC 1.0.I want to display tabpanel based upon permission.i.e. i have written function which will return boolean value and based upon that value i want to display tab panel on my view page. Following is the function.Here i am passing tabName="UserBrowseTab" as my Database have ent...

in asp.net mvc, can i make a default editor template for enum?

which i mean can i do something like this : <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %> <% -- any code to read the enum and write a dropdown --> and put it in the EditorTemplates folder under the name (Enum.ascx) ? //-------------a work around my problem but it's not what i need------// here is m...

MVC Routes: Adding an optional parameter at the beginning of a route

I have the following routes setup in my route config file. I have a config reader that maps these to MVC-style routes. [route name="customers" url="customers/{statename}/{marketname}/{pagenumber}"] [controller name="Customers" action="Display" /] [/route] [route name="pcustomers" url="{customername}/customers/{statename}/{ma...

ASP.NET MVC/LINQ - retreiving tables and number of connections

Still extremely new to the whole MVC/LINQ thing. I'm in the processes off building a blog, and I need to build a table for the posts, and within each post build a table for the comments of that post. To build the tables, I'm doing something like: postsTable = (new DataContext(connectionString)).GetTable<Post>(); Unfortunately for eac...

accessing HttpContext.Request in a controller's constructor

I'm following this ASP.NET MVC tutorial from Microsoft: My code is slightly different, where I'm trying to access HttpContext.Request.IsAuthenticated in the controller's constructor. namespace SCE.Controllers.Application { public abstract class ApplicationController : Controller { public ApplicationController() ...