asp.net-mvc

How can i validate partial view that is returned from controller.

Hi experts, I have a view page with ajax.action link which returns a partial view from controller and render it to divid as updated target id.But I could not perform client side validation on that partial view.Can i have solution for it? ...

Error when passing additional ViewData to strongly typed Partial View

My partial view isn't being loaded. Please find my code snippets, I can't figure out what is wrong. Help please. The error message is: c:MvcUI\Views\Project\Details.ascx(42): error CS1950: The best overloaded Add method 'System.Web.Mvc.ViewDataDictionary.Add(System.Collections.Generic.KeyValuePair)' for the collection initializer ...

Exception in mvc.net controller

In mvc .net c# i have over loaded OnException action in my base controller In controller action I have generated zip file using Ionic.Zip.dll The code for this is like foreach (var file in filesToarchive) { zip.AddFile(@file.FilePath); } zip.Save(Response.OutputStream); var rept = reports.First(); return File(Response.OutputStrea...

How to convert TextBoxes with null values to empty strings

I may be out of date, but one principle I adhere to is avoid nulls as much as possible. However what I have found is that for a strongly typed view in which the user inputs the properties of an object I want to save, if some fields are not entered they are assigned as null.Then when you try to save the changes, the validation fails. So r...

ASP.NET MVC SiteMap with Ninject controller factory error

I am trying to use the ASP.NET MVC Codeplex Sitemap project with Custom Dynamic Node provider. This is my node provider code. It uses some repository to access the DB. I actually don't use DI in this class but the application inherits NinjectHttpApplication and the Sitemap has problems acquiring controller. public class ContentPageDynam...

How ASP.NET MVC applies .input-validation-error to a textbox when the form is redisplayed for failed value?

Hello, I've asked a question to know why, in my application, textboxes are being highlighted (i.e. red border and pink-shaded backgroung are applied to the textbox) when I use modelbinding to validate the model (TryUpdateModel()) but not when I validate manually (ModelState.AddModelError). It has been 2 days now without any answer. I've...

MVC2 application with Ckeditor "potentially dangerous Request.Form...

I'm getting the "Potentially dangerous Request.Form request value was detected from the client" exception when im using my FCK editor. How could encode before submit the form, or disable this validation without disable the Data Anotations validation? This is the code of my view: <% using (Html.BeginForm()) {%> <%: Html.Valida...

ambient values in mvc2.net routing

Hello Everyone, i have following two routes registered in my global.asax file routes.MapRoute( "strict", "{controller}.mvc/{docid}/{action}/{id}", new { action = "Index", id = "", docid = "" }, new { docid = @"\d+"} ); routes.MapRoute( "default", ...

How to pass Model field value into a javascript variable?

<%: Html.HiddenFor(model => model.Name) %> <script> var name = <%: Model.Name %> alert(name); </script> ...

Pointers for writing a unit test for a Razor based View needed.

I'm trying out the new Razor view engine with MVC 3 Preview 1 and would really like to write a simple unit test using NUnit/Moq. I haven't seen any examples of this actually being done yet - despite it being one of the real selling features on Razor. So, if I have a Controller, that uses a DBConext object (EF4 CTP code first) and the vi...

How can I bind a model object using Controller.TryUpdateModel<TModel> Method (TModel, String, String[], String[]) to exclude some properties?

Hello, Let's say I've the following model public class MyClass { public type1 Property1 { get; set; } public type1 Property2 { get; set; } public type1 Property3 { get; set; } public type1 Property4 { get; set; } public type1 Property5 { get; set; } } I would, for instance, like to bind only the first 3 properties. How ca...

System.MissingMethodException: No parameterless constructor defined for this object.

I'm using MVC 2.0 with a Html.ListBoxFor as below: <% using (Html.BeginForm()) { %> <input type="submit" value=">" /> <%= Html.ListBoxFor(x => x.lstTest, new MultiSelectList(new [] {"someone", "crap", "why"})) %> <% } %> When I click the input submit button below with nothing selected, it posts back fine, when I ...

Keep track of who is on website right now

How would I keep track of number of current sessions on my website? ...

Unable to access cookie in HttpRequest

I'm trying to do a “get” of a page, and pass in a list of ids that is stored in my cookie. My assumption was that it would be possible to get the cookie with the list from my request. However, I don’t get the cookie on the server side as I would expect. I only get a “user” cookie, but that doesn’t contain my info. I want to try to avoi...

How to turn off Auto correct for braces and coded elements in a Visual Studio MVC View

I am using Visual Studio 2010, but this applies to VS 2008 as well. In my MVC views I prefer to write my coded elements as follows: <% if (somecondition) { %> <p>something</p> <% } else { %> <p>something else</p> <% } %> This just looks more readable to me than the following which is what VS auto corrects my code to look like...

Rendering image as hyperlink in ASP.NET MVC without writing any helper extension method

Currently, I have code like this : <% if (consumer.IsDischarged) { %> <%= Html.ActionLink("<img src=\"../../Images/ConsumerImages/computer_go.png\" alt=\"discharged\" style=\"border:\"0\"/>", "Details", new { id = consumer.ApsId })%> <%} %> Basically I want to show the hyperlinked image whenever the status of the isDi...

LINQtoSQL - How do I get my query to recongize which table I want?

Hello SO, I'm using LINQtoSQL to create cascading deletes IE: if Category is deleted then all the Products in that category are also deleted. I have a Products repository set up already (IProductsRepository) and now I'm working in my Category repository to add the business domain logic for the cascade. Products repository has this met...

Is Razor view with ASPX .Master page possible?

Is it possible to keep my existing .master page and have it used with a new ASP.NET MVC 3 Razor view? I tried this: @{ LayoutPage = "~/Views/Shared/Site.master"; } And it gives me this error message: The file '~/Views/Shared/Site.master' could not be rendered, because it does not exist or is not a valid page. ...

Add a calculated field to asp.net mvc model

I'd like to have a list that will shorten a field value if it is too long from a linked Entity Data Model. Something where I could take the following: <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<MvcDR.Models.DONOR_LIST>>" %> <asp:Content ID="Content1" Content...

I have a parameterless public constructor but I am still getting an error saying I need one.

The error is: An error occurred while creating a controller of type 'foo'. If the controller doesn't have a controller factory, ensure that it has a parameterless public constructor. However, fooController has a parameterless public constructor. I'm using the default factory. As far as I know, this code was working, and n...