asp.net-mvc

ASP.Net MVC - Null Objects in Views

I'm looking for a clean way to handle null object references in LINQ to SQL model class when they are passed to a View. Simple example. TableA has a FK into TableB. The FK relationship may or may not exist for any row in TableA. My LINQ to SQL classes express this relationship as ClassA.ClassB.Property, but in some instances ClassA.Cl...

Stack Overflow Question Routing

If you review a SO question URL you will see that an ID and a "SLUG" are passed to the Questions controller: http://stackoverflow.com/questions/676934/what-do-you-need-to-write-your-own-blog-engine. What I find interesting is you can change the "SLUG" portion of the URL without affecting the application's ability to route the request exa...

Why is this MVC route not working?

Hi folks, here are two routes from my global.asax file. I'm trying to go to the second route and I'm getting a default 404 resource not found error. When i remove the first route (listed in this example), it works. How can i fix this, please? Snippet of global.asax code // GET: /user/PureKrome/Alert/69 routes.MapRoute( "User-Ale...

What is the best way to create printable letters from an MVC application?

What's the best way to create printable letters from an MVC application? I'm looking for sort of a mail merge thing from my app that prints a form letter with various values filled in. In ASP.NET, I previously did this by creating an HTML document and displaying it as application/msword, but I did that with code-behind, which isn't an (...

How to map form values to an object for ASP.NET MVC HTTP-Post scenario?

Hi folks, i have a simple form for an ASP.NET MVC application. I have a form property that is named differently (for whatever reason) to the real property name. I know there's [Bind(Exlcude="", Include="")] attribute, but that doesn't help me in this case. I also don't want to have a (FormsCollection formsCollection) argument in the...

Mocking and HttpContextBase.get_User()

I want to mock the User property of an HttpContext. I'm using Scott Hanselmans MVCHelper class and RhinoMocks. I have a unit test that contains code, like this: ... MockIdentity fakeId = new MockIdentity("TEST_USER", "Windows", true); MockPrincipal fakeUser = new MockPrincipal(null, fakeId); using (mocks.Record()) { Expect.Call(f...

What happened to System.Web.Mvc.dll?

A colleague emailed me an example ASP.NET MVC project that won't build on my machine as it contains a reference to System.Web.Mvc.dll In the .csproj file: <Reference Include="System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" /> I have VS2008 SP1 installed and can create new...

View does not display updated values asp.net mvc

We want to perform some calculations on some values in a view...so when the user enters a value in a input...we want to go back to the server...perform the calculations and "refresh" the view with the new values...With the code as it is now, it enters the correct (...or at least the one I ask it to) controller action, correctly performs ...

Set ViewData outside the controller

I'm trying to create a logger that will write the queries LINQ executes to the page formatted with the great javascript library SyntaxHighlighter. For that, I've set the DataContext's Log property to my custom logger, which is working well. Now I just need to get the current Controller object (outside the controller execution context) ...

ASP.NET mvc on mono 2.2

Hi, I am having a trouble. I am trying to run asp.net mvc 1.0 on mono 2.2.I have copied the system.web.mvc.dll to bin directory. I have done HttpContext.Current.RewritePath("/Home/Index");. Still I am having te error: Server Error in '/' Application The incoming request does not match any route Description: HTTP 500. Error processing r...

Hijacking Form Submission on ASP.NET MVC with jQuery (or other)

I'm using ASP.NET MVC (v1.0) on an app and want to integrate simple client-side form validation. IE: Numeric-Only fields, required fields, etc. Is there good, and potentially eye-candy fancy, method of validating in jQuery on the client that will cancel form submission on failed validation? I've perused and experimented with quite a fe...

How to persist a data set between MVC calls

The following setup kind of works, but it's not the proper use of TempData, and it falls down after the first use. I suspect I'm supposed to be using ViewData, but I'm looking for some guidance to do it correctly. In my Home controller, I have an Index action that shows which members need to have letters created: Function Index() As Ac...

Best practice for removing Database calls from MVC Controller classes

Hi All, I have an Action method in an ASP.NET MVC Controller class that handles form posts from a fairly basic "create/edit a user" page. I'm new to MVC so I've been following code samples from various Microsoft tutorials, this is how the method looks currently: [AcceptVerbs(HttpVerbs.Post)] public ViewResult Save([Bind(Prefix = "Servi...

Best practice for Parent / Child UI design in ASP.Net?

Coming from a desktop client background, with no real data-driven web design experience, I am studying ASP.NET UI design to determine the best UI pattern for Parent/Children data. I always tend to experiment with Parent/Child presentation when learning a new UI platform, so that is where I have started here. Thinking I should use ASP.NE...

Html.ActionLink for non-standard routing

I have a route definition like this: routes.MapRoute( "Pagesize", "{controller}/{action}/pagesize/{pagesize}", new { controller = "Home", action = "Index", pagesize = 10 } ); When I use <%= Html.ActionLink("MyText", "myaction", new { pagesize = 10 }) %> it renders as <a href="/myaction/?pagesize=10">MyText</a> I can...

Tracking anonymous user activity

I need to track anonymous users with enabled cookies. Basically, they will go through the site, interact with it, and I would like to give them the best possible experience without requiring actual registration. Later on, if they want, they can register and their site activity will be tied to their new account. Something like Stackov...

How can I use the DRY principle to in ASP.NET MVC to refactor this code?

I have several methods in one of my controllers that does this: ViewData["Customers"] = LoadCustomers(); ViewData["Employees"] = LoadEmployees(); ViewData["Statuses"] = LoadStatuses(); etc...... Here is LoadCustomers(), but LoadEmployees, LoadStatuses and all the others are virtually the exact same logic: private static SelectLis...

how to add a code-behind page to a view or partial view

I notice with the latest version of ASP.NET MVC that a View no longer defaults to having code-behind classes. How do I go about adding a code-behind class now to a View or Partial View?? ...

How to provide a SQL command line interface (like osql) to a MSSQL database via webpage in .NET MVC (c#)

I'd like to provide a command line interface to my db that allows the user to enter MULTIPLE database commands or queries (separated by line breaks in the textarea) For each line, if its a query must return the results and if its a command, whether or not it was successful - thus allowing the user to paste a script into the text area an...

How to bind nested array element property value to TextBox in ASP.NET MVC

Hi, I have model public class User { public User() { Addreses = new List<Address>(); } public String Name { get; set; } public String LastName { get; set; } public List<Address> Addresses { get; private set; } } public class Address { public String Street { get; set; } public String City { get; ...