asp.net-mvc

ModelState.IsValid for invisible controls

I am working on MVC with C#. I have 2 radio buttons. On selecting first radio button, a textbox will be shown which allows to enter date values. <%= Html.TextBox("ReceivedDate")%> on selecting the second radio button, the textbox gets hidden. For the first time, when i select first radio button and entered date and clicked N...

Debugging ASP.NET MVC source?

Trying to debug into ASP.NET MVC 1.0 source, I followed instructions like these, basically remove reference to system.web.mvc from my web project and add the source project I downloaded instead. Now, I have this problem, The type 'System.Web.Mvc.FormMethod' exists in both 'c:\Windows\assembly\GAC_MSIL\System.Web.Mvc\1.0.0.0__31b...

Dynamically Adding a ViewUserControl in ASP.NET MVC

I am wondering if there are any known issues with adding a ViewUserControl at run time (to a ViewPage). It works fine if I add the control declaritively but not if I add the control programmatically (in the code behind file in this case). I don't get an error, it just does not render the control but stepping through the debugger does con...

Issues with Exported Crystal Report to Word Document

I am having a minor issue playing with my exported Crystal Report, I can generate the reports just fine on our website, however when I attempt to export them to Word documents I don't quite get a document I can do much with. i.e.: I can't position the generated text anywhere in the document, it is almost 'frozen' in place. I would ex...

C# MVC: Trailing equal sign in URL doesn't hit route

I have an MVC route like this www.example.com/Find?Key= with the Key being a Base64 string. The problem is that the Base64 string sometimes has a trailing equal sign (=) such as "huhsdfjbsdf2394=". When that happens, for some reason my route doesn't get hit anymore. What should I do to resolve this? My route: routes.MapRoute( "...

ASP.NET MVC Model & Business Objects

I am looking for some guidance on how to incorporate business rules into an asp.net mvc application and how they relate to the model. First a little background so we know what kind of solutions are relative for this question. At work we use WinForms, MVP, BusinessObjects, DataAccessObjects, and DataTransferObjects. The boundaries of...

Override ASP.NET forms authentication for a single page

In our ASP.NET MVC application, we automatically redirect users to a log-on page via the <authentication> section of <system.web> when they attempt to access an authorized-only page. The problem is that one action in the middle of the application, designed to be used by a tool, needs to return a straight-up HTTP 401 response on bad acce...

Key risks when using ASP.NET MVC for the first time

We are planning to use ASP.NET MVC on a relatively important (to the business) project. The development team comprises 4 developers and a Technical Lead. 2 of the devs and the Tech Lead have worked together before on ASP.NET WebForms project and are confident using that technology. We cringe a little when we look back at some of the app...

How do you name your ViewModel classes?

What kind of naming convention is appropriate for ViewModel classes? Example: for HomeController, Index view? HomeIndexViewData doesn't seem right. ...

C# MVC: ViewModel Base Class (for Master Page Information) ?

How would you push strongly typed information in MVC to the master page? Would you have a ViewModelBase class that contains master page information and inherit from it for every view model, or is there a better approach? Thanks :) ...

ASP.NET MVC relative path to JavaScript

I am trying to reference the jQuery library in my master page like so: src="<%= ResolveUrl("~/Scripts/jquery-1.2.6.js")%>" type="text/javascript"> The source for the page shows: <script src="/DocumentManagement/Scripts/jquery-1.2.6.js" type="text/javascript"></script> which seems to be correct since my site's url is http://servern...

C# MVC: What is the difference between <%# and <%=

What is the difference between <%# and <%= in ASPX inline code? ...

C# MVC: Url type not available in my view?

I see endless examples that involve "Url.Action" in a view to generate a URL dynamically. (See example code below.) The problem: The type/class "Url" doesn't exist in my views! No IntelliSense, and compiling the site results in a "Type expected" exception. How do I get it in there? Source Code Snippet (this is from an example): <form...

Add empty value to a DropDownList in ASP.net MVC

I'm building a data entry interface and have successfully bound the columns that have reference tables for their data using DropDownList so the user selects from the pre-configured values. My problem now is that I don't want the first value to be selected by default, I need to force the user to select a value from the list to avoid erro...

C# MVC: Use Attribute to create Request IP constraint

I would like to do the following (Pseudo Code): [InternalOnly] public ActionResult InternalMethod() { //magic } The "InternalOnly" attribute is for methods that should check the HttpContext request IP for a known value before doing anything else. How would I go about creating this "InternalOnly" attribute? ...

Recursion in an ASP.NET MVC view

I have a nested data object for a set of items within categories. Each category can contain sub categories and there is no set limit to the depth of sub categories. (A file system would have a similar structure.) It looks something like this: class category { public int id; public string name; public IQueryable<category> cat...

Does Asp.net MVC help creating n-tier solutions?

My opinion is it does and it doesn't. It does separate logic and data from UI, but it still crams it all together into a single point application. That's why I think it doesn't really, because Controllers are business logic, Views are UI, Models are DAL. These are now just layers within the same app. But are layers supposed to be the...

C# LINQ: Sequence Contains No Elements Error (but I want to check for null!)

Hello, I have the following problem: public Boolean Exists(String userName) { IRepository<User> = new UserRepository(); User user = userRepository.First(u => u.Name == userName); if (user == null) return false; // Exists! return true; } The problem is now, that I can't check the User object for null. Before I...

Issue when trying to route a path that ends with a '.'

I'm trying to route a path like this: http://www.wikipediamaze.com/wiki/Washington,_D.C. The routing framework is not picking this up as a valid route and giving me a "Cannot find resource" error. Anyone know how I can get around this? It's not even getting to my controller factory so it's as if it doesn't even recognize it as a route...

404 Error w/ ASP.NET MVC Routing on ISP

I have a simple ASP.NET MVC 1.0 site w/ Home, Upload, and About links based upon the default project template for an ASP.NET MVC Project. The Global.asax.cs has the following route. routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", ...