asp.net-mvc

MVC Validation using Data Annotations - Scenarios where it doesn't work, Alternatives?

So I have been using data annotations for my validation in an MVC project and they seem to work in most scenarios. Here are two examples in my current project where they don't seem to fit and I am unsure of the best place to put the validation. 1) I have a Join League page that contains a form where the logged in user enters their t...

ASP.NET MVC output cache with dynamic fragment

How could I cache an entire page except a bit at the top which says something along the lines of "Welcome back, Matt! | Log Out" if the user is logged in and so-on? I'm using ASP.NET MVC 2. ...

Jquery thickbox to work with Url.Action link in Asp.net mvc

Hi, I want to implement a Jquery thickbox to show an image that is generated from my database in ASP.Net MVC. My link looks roughly like this: <a href="<%=Url.Action("ShowPhoto", "Item", new { id = pic.pictureID }) %>" class="thickbox"><img src="<%= Url.Action( "ShowThumbnail", "Item", new { id = pic.pictureID } ) %>" alt="" width="1...

ajax and security controler

I'm using jQuery Ajax to post and when success get the data and replace some items that's work good if i add some security to the controller like that [Authorize] public ActionResult ......... If the user logged in every thing go OK but when the user not logged or not authorized it should be redirected to the login page As I'm using...

Structuring several mostly-static pages in ASP.NET MVC

Might not be a very consequential question, but... I have a bunch of mostly-static pages: Contact, About, Terms of Use, and about 7-8 more. Should each of these have their own controllers, or should I just have one action for each? Thanks in advance. ...

Object reference not set to an instance of an object

In this line of code <% var tmp = int.Parse(ViewData["numOfGroups"].ToString()); %> I have error:Object reference not set to an instance of an object. How correctly convert ViewData["numOfGroups"] to int? ...

Alternative places to register routes to global.asax

It's most common practice to register routes in Application_Start event within global.asax.cs/vb file. But you need to have access to this file to do so. Fine. I either don't have or don't want to. I'm trying to integrate Asp.net MVC application into a Sharepoint 2010 site and don't want to create my custom global application class that...

What is .net 3.5 sp1 ?

(1) What is service pack ? (2) I want to work with mvc. So I have installed visual studio 2008 then I tried to install mvc 1.0 but there is error that you have to install 3.5 sp1.Then is it necessary to install 3.5 sp1 or 3.5 .net framework is installed automatically when I installed vs 2008 ? (3) I tried to download 3.5 sp1 but it ...

Function to display a DateTime string or an empty string

I tried to create a view helper which takes a DateTime object and returns a string. If the DateTime object equals a new DateTime(0), the function returns an empty string. Otherwise return a formatted DateTime string. This works so far. public static string DateTimeOrEmpty(this HtmlHelper htmlHelper, DateTime dateTime) { return date...

ASp.net MVC route page not found

i have this url http://localhost:17643/category/1/Home/Arts/ It shoud redirect to home/index?idCategory=1 Instead i get a page not found. the RouteRegistrar is: routes.MapRoute( "Category", "category/{idCategory}/{categories}", new { controller = "home", action = "index", idCategory = "" } ...

Resource (RESX) files messed up

I had a resource file named Localize.resx, which contains English strings. I copied and pasted it inside the same folder(App_GlobalResources), VS created a copy, I renamed the copy to Localize.sl.resx and the original to Localize.en.resx. Now everything in codebehind files (Localize.en.designer.cs) is gone. Deleting the designer file and...

MVC2 and Session Start Event

The Setup: Account controller with the typical logon / logoff stuff that comes baked in from the template. Not much modification here on the logon page. Using a custom membership provider (SQL), but I don't think that is impacting what I am trying to do here. The Requirements: The client wants to handle licensing by limiting concurr...

Test Function in MVC Project

So I want to test one of my Functions in my Web Project, but it's not actually connected to anything in the project yet (someone else is working on that part). The Function takes in an "ID" field, goes off and does some queries and gets some data, performs some calculations on it, and then writes a bunch of lines to a FileStream and retu...

skipping over potential nulls c#

I have this block of code that eventually get serialized to JSON, for use in the Jquery FullCalender plugin. The ToUnixTimeSpan method taskes in a DateTime object and returns the number of seconds since 1970. DateEnd could be null. In this block of code how do i test for the null and skip the end = ToUnixTimespan(e.DateEnd), if Dat...

jqModal and ASP.NET MVC

Hi everyone! I want to create a simple form for adding new products using jqModal. View / Home / Index.aspx: <script type="text/javascript"> $(document).ready(function () { $('#addProductControlSection').jqm({ modal: true, ajax: '<%: Url.Action("AddProduct", "Home") %>', onHide: myA...

Redirect to another server - ASP MVC

Hello, Does anybody know how to redirect to another server/solution using ASP.NET MVC? Something like this: public void Redir(String param) { // Redirect to another application, ie: // Redirect("www.google.com"); // or // Response.StatusCode= 301; // Response.AddHeader("Location","www.google.com"); // Response.End(); ...

ASP.NET MVC: Redirect user to route with parameters from a drop down list

I have a drop down list (<select> tag) filled with bikes (more specifically their names). When a user selects a bike in the list I want them to be redirected to the details page for the selected bike. I have a route for bike details as such: routes.MapRoute("BikeDetails", "bike/{bikeId}", new { ...

How to specify a min but no max decimal using the range data annotation attribute?

I would like to specify that a decimal field for a price must be >= 0 but I don't really want to impose a max value. Here's what I have so far...I'm not sure what the correct way to do this is. [Range(typeof(decimal), "0", "??"] public decimal Price { get; set; } ...

Paging and Sorting Grid in ASP.NET MVC

Hi, I'm trying to implement a paging and sorting list in ASP.NET MVC without using MVContrib grid or javascript (needs to be seo friendly). I have constructed my action with the following signature: ActionResult List(int? page, string sort, string direction); The problem I have though is getting both the paging and the sorting to wor...

SSI-like feature in ASP.NET / ASP.NET MVC

This may be a heretic question in a way. We have large site where lot of pages are still in ASP. Mostly, there are not really dynamic but they include (via SSI or Server.Execute) periodically regenerated chunks of HTML. It may look like a poor man's caching, but it has been working really well and I'm guessing that Microsoft has heavily ...