asp.net-mvc

how do i set disabled attribute on html textbox in asp.net-mvc ?

i am trying to dynamically set the disabled attribute on the html textbox and having issues i tried this in my view: string disabledString = ""; if (SomeLogic) { disabledString = "disabled"; } Html.Textbox()...new Dictionary<string, object> { { "maxlength", 50 }, { "disabled", readOnlyState } })%> so as you can see i am s...

HtmlHelper NameFor method

Is there any Html.NameFor feature already implemented, that get the name html attribute for a model item? I'l like to use the following code in my Razor view: <input type="text" value="@Model.User.Email" name="@Html.NameFor(x => x.User.Email)"> ...

Using ASP.NET MVC OutputCache while varying View content based on whether user is authenticated

I'm building an ASP.NET MVC 2 site where I'm using the OutputCache parameter heavily. However, I have a concern: using such caching may interfere with authentication. On all of my pages, I display whether the user is logged in or not. Furthermore, in some of my Views, I do filtering based on user role to determine whether or not to disp...

Internet Explorer $.ajax / MVC JSON call failing

I have a relatively simple example of an MVC page that is using jQuery to make a POST to get some JSON data and then just show a success/failure message when it is done. The code works perfectly fine in the other browsers but in IE7/8 it seems to fail 4/5 times. Here is the MVC View Page: <asp:Content runat="server" ContentPlaceHolderI...

C# ASP.NET MVC User Control

I want to insert a user control on to a master page The user control is a basic menu that lists categories of items I want to pull the category list dynamically from SQL Server I can do this in web forms using code behind, but how do you go about this in MVC? Thank you Categories.ascx: <%@ Control Language="C#" Inherits="System.Web.M...

Is there a way for MVC Partial View retrieved using jQuery to keep UI CSS Styling?

Hi All, I have an MVC 2 project, consisting of a MasterPageView a child View called Index and a number of PartialViews. The PartialViews are loaded into the Index View using the jQuery Ajax method $.get(....). My problem is that I am styling the buttons using jQuery UI like: $('button').button(); but I find that I need to do this on...

How do you decide on the means of passing model data from asp.net mvc controllers to views?

There seem to be multiple means of passing model data from controllers in asp.net mvc to views. Its not clear to me if there's a recommended approach in the mvc v1 and v2 releases or if like most things in life, it depends. I've seen several approaches: Option 1 - Populate the controller's ViewData dixtionary in either an icky string-ba...

ASP.NET MVC - Loading Maxmind dat file

Hello, I am planning to use Maxmind's DAT file to provide some basic geolocation capabilities in an ASP.NET MVC application I'm developing. The DAT file is approximately 17mb and I'm wondering what the best approach would be to load this in my application - obviously I don't want to load it every time some geographical information is req...

How to clear textboxes defined with MVC HTML helpers

I can't figure out how to do this very simple thing: My page contains a set of textboxes that a user can fill out to add an item to a list. Then the item shows up in a dropdown list. At that point, I want the "add" textboxes to be cleared. This is the behavior expected by most users, I think. The item has been added; now the textboxes ...

how to edit objects with other ie IList<object> or simple object attached to it?

Hi Im stuck on how to do this the best way. In my case I got a Product and it got a Manufacturer Object. So what I do is I pass the product to the view to edit. But when I do the save I look at the product object and Manufacturer is now null. I tried to do a hiddenfor for the Manufacturer Object like I do with id for the product, but t...

How to set the S-MaxAge CacheControl value in an ASP.NET app?

Hi folks, I'm trying to set the cachability of an ASP.NET resource. So if I goto /foo/show it will show a View for some resource, and cache this for a few hours (for example). To do this, I'm using the OutputCache attribute which decorates my Action Method. The details of this cache (against this action method) are found in the web.conf...

Using Response.Filter with Response.TransmitFile

I'm using Response.Filter in order to implement stream compression in accordance with HTTP Request Header Accept-Encoding Here's the important stuff: if (AcceptEncoding.Contains("deflate") || AcceptEncoding == "*") { HttpApp.Response.Filter = new DeflateStream(PreviousOutputStream, CompressionMode.Compress)...

What are the conventions for mapping collections with the default model binder?

In MVC 2, what is the default mapping behaviour for the binder. I saw it once in a blog, but cannot find it again. Particularly in regards to list items. From memory it is something like this: {ModelName}[{id}].{Proptery} Any help would be greatly appreciated, especially an online article that refers to this. ...

MissingMethodException thrown when trying to mock HtmlHelper with Moq

When attempting to follow the article on mocking the htmlhelper with Moq I ran in to the following problem. The exception is thrown on creation of the htmlhelper. I am only guessing that castle windsor is being used (by seeing the error message). The exception: MissingMethodException occurred Constructor on type 'Castle.Prox...

how to RedirectToAction to home page?

How to redirect a page to home page? if (p == -1) return RedirectToAction("Index"); this opens webpage like http://abc.com/Index in url i want just http://abc.com ...

button click event in asp.net mvc

I have a button and a label. on clicking on that button i want to change the text of label. How can i do this in Asp.net mvc 1.0. ...

Copying Http Request InputStream

Hi, I'm implementing a proxy action method that forwards the incoming web request and forwards it to another web page, adding a few headers. The action method works file for GET requests, but I'm still struggling with forwarding the incoming POST request. The problem is that I don't know how to properly write the request body to the o...

Create view is posting null objects

Should be an easy question to answer. I am trying to create an object in a view. The class that contains the object consists of a User class and a password. When I click on the submit button, the Controller picks up null values for Password and User. See below the Container class, the Controller and the View; public class UserExtended {...

Check Checkbox based on value in CSV

If I have a csv of 23,56,78 and I have a whole bunch of checkboxes three of which have these values, is there an easy way to select them? I suspect the answer is I need to itterate through my list and use a selector but is there another way? ...

mvc2.net how to remove ambient route values

Hello Everyone, in my mvc2 application i have an action link like <%=Html.ActionLink("dash.board", "Index", pck.Controller, new{docid ="",id = pck.PkgID }, new { @class = "here" })%> docid is set to empty string because i want to clear ambient value of docid that is present in request context. i have gone through a lot of material o...