asp.net-mvc

JQuery validation without requiring MS scripts in asp.net mvc2 project

Is it possible to use the new client side validation features of asp.net MVC 2 without having to use the MS scripts (MicrosoftAjax.js, MicrosoftMvcAjax.js, MicrosoftMvcValidation.js)? I use JQuery throughout my application; JQuery has a great plugin for validation and I don't really want to force my users to load MS scripts just for v...

How to Unit Test HtmlHelper similar to "using(Html.BeginForm()){ }"

Can somebody please suggest how I could write a Unit Test with Moq for following HtmlHelper method? public static HtmlTagBase GenerateTag<T>(this HtmlHelper htmlHelper , object elementData , object attributes) where T : HtmlTagBase { return (T)Activator.Creat...

How to replace tokens in the master page in asp.net mvc?

I have a master page in my asp.net MVC project, which has code like this: <div id="menu"> <ul> <li><a href="#" class="current">home</a></li> <li><a href="#">add image</a></li> <li><a href="#">contact</a></li> </ul> </div> Depending on what page I am on, I'd like to move the c...

How to conditionally add a bit of CSS to a page in ASP.NET MVC?

I have a CSS stylesheet defined in the Master Page of my project. On one of the pages/views that inherits from the Master Page, I need to add another CSS stylesheet (I could also add it inline, though I'd rather not). However, how to do this escapes me. Is this even possible? ...

How to generate just the URL of the Controller method in ASP.NET MVC

So Html.ActionLink("Report", "SendMail", "Misc", new { id = Model.ImageID }, null) will generate a nicely formatted link. <a href="http://localhost:3224/Misc/SendMail/5"&gt;Send Mail</a> How can I generate just the URL of the link, short of parsing the output of Html.ActionLink? ...

Configuring security in ASP.NET MVC at runtime

Is it possible to have security in ASP.NET MVC configurable at runtime? For example, if I have a controller that has been marked as [Authorize(Roles="Admin")] Is there a way to add/remove roles at runtime? Or, do you have to change it in code and re-compile? ...

How to handle relative paths in ASP.NET MVC?

I have a master page which references a style in the following manner: <link rel="stylesheet" type="text/css" href="../../Content/Style.css" /> All my pages inherit from this master page. And this works well when the URL is http://www.domain.com/home/details/5, however the URL is http://www.domain.com/home/create, then, of course, St...

What is the best way to work on a MVC project online?

In a regular Web Forms application, I could upload the files to a web server and just open the web server in Visual Web Developer and it worked great, but because MVC is a project and not a web application, I can't just upload the files regulary and still open it in Visual Web Developre normally... So here comes the SVN, but the pro...

What is the best method for updating all changed data in EF 4?

I try to create some method that can update any changed data from changed Data object (this object is generated by ASP.NET MVC) to old Data object (this object is retrieved from current data in DBMS) like the following code. public static bool UpdateSomeData(SomeEntities context, SomeModelType changedData) { var oldData = GetSomeMod...

ASP.NET MVC ajax chat

I built an ajax chat in one of my mvc website. everything is working fine. I am using polling. At certain interval i am using $.post to get the messages from the db. But there is a problem. The message retrieved using $.post keeps on repeating. here is my javascript code and controller method. var t; function GetMessage...

How to handle missing files on MVC

What is your preferred way to handle hits to files that does not exist on your MVC app. I have couple of web apps runing with MVC and they are constantly getting hits for files folders etc. that does not exist in the app structure. Apps are throwing exception: The controller for path could not be found or it does not implement IControl...

ASP.NEt MVC 2 Client validation function in Ajax form

Hello, My problem is the following: I'm using client validation function of the MVC 2.0 framework. Everything is nice, when I use the validation in a simple form. But when I use an Ajax form, and I update the fields of the ajax form, the client validation doesn't work. I think about, I have to refresh the validation after the ajax c...

ASP.NET MVC - Add XHTML into validation error messages

Hi, Just starting with ASP.Net MVC and have hit a bit of a snag regarding validation messages. I've a custom validation attribute assigned to my class validate several properties on my model. When this validation fails, we'd like the error message to contain XHTML mark-up, including a link to help page, (this was done in the original W...

How to check if returning View is of type PartialViewResult or a ViewUserControl

In the method CreateView() (check my View Engine below) or in my custom action filter (also below) I have to somehow check if the View we are requesting is a ViewUserControl. Because otherwise I get an error saying "A master name cannot be specified when the view is a ViewUserControl." when I have "modal=true" in QueryString and the Vi...

How to use db4o IObjectContainer in a web application ? (Container lifetime ?)

I am evaluating db4o for persistence for a ASP .NET MVC project. I am wondering how I should use the IObjectContainer in a web context with regards to object lifetime. As I see it, I can do one of the following: Create the IObjectContainer at application startup and keep the same instance for the entire application lifetime. Create on...

ASP.NET MVC Viewmodel trouble...

I've already started similar topic, but still didn't find final solution... So here I am with new one :) ... I'm developing NerdDinner from scratch and now I came to point where I define DinnerViewModel. Following these instructions (starting from Listing 5) I came to this: namespace Nerd.Controllers { // View Model Classes ...

DataAnnotations in ASP.NET MVC 2 - Stop MVC from applying RequiredAttribute to Non-nullable DateTime etc. properties

Im trying to create a custom version of the RequiredAttribute to replace the built in one and I've got it working for properties that have strings values, but with properties that are DateTime or integer for example, the default RequiredAttribute seems to be applied automatically (IF the property is not nullable!) My problem is that i w...

Edit and Create view using EditCreate.ascx partial in ASP.NET MVC

If you look at the NerdDinner example of creating and editing dinners then you see they use a partial (ViewUserControl or ASCX) DinnerForm to put the functionality of creating and editing dinners into one file because it is essential the same and they use it using RenderPartial("DinnerForm"). This approach seems fine for me but I've run...

Asp.net Mvc 2: Repository, Paging, and Filtering how to?

It makes sense to pass a filter object to the repository so it can limit what records return: var myFilterObject = myFilterFactory.GetBlank(); myFilterObject.AddFilter( new Filter { "transmission", "eq", "Automatic"} ); var myCars = myRepository.GetCars(myfilterObject); Key question: how would you implement paging and where? Any link...

Asp.Net MVC 2: What's the standard way to keep selected values in forms?

Say you have a few DropDownLists that filter data: Car Make: [Ford,Chevrolet,etc] Car Year: [2010, 2009, 2008, etc] Car Model: [LT, SLT, etc] And you make a selection and not show that DDL again. Is there any standard place to maintain previously selected values? This is for a "drill down" menu system. ...