asp.net-mvc-2

Does ReadOnly(true) work with Html.EditorForModel?

人盡茶涼 提交于 2019-11-27 16:49:27
问题 Consider the following setup: Model: public class Product { [ReadOnly(true)] public int ProductID { get; set; } public string Name { get; set; } } View: <%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MvcApplication4.Models.Product>" %> <asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"> Home Page </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> <%= Html.EditorForModel()

How to URL encode parameters in ASP .NET MVC

为君一笑 提交于 2019-11-27 16:07:05
I have the following code in my view: <%= Html.ActionLink( "View item", "Index", "Items", new { itemName = Model.ItemName }, null) %> I have a problem when the item name contains a sharp (#) or the percent symbol (%). When the item name is "name#with#sharp#" , the controller receives only the first part of the name until the first sharp (only receives "name" ). When the item name is "name%with%percent" I get an error: HTTP error 400 - Bad request. I not sure if this is a problem with the URL encoding, because it works with other conflictive chars such as: ; = + , ~ [blank] Do you know how

JQuery DataTables .Net Server Side Pagination Issues

依然范特西╮ 提交于 2019-11-27 15:50:39
问题 I'm working on a bug fix right now for an application at work where the prior developer (since gone) didn't bother to paginate the data results on a page meant specifically for listing out data results. This of course has reared it's ugly head as users are starting to see long running script errors in IE. This, combined with the sheer data volume size, is making web pages nearly useless. Fast forward to my attempts to fix it and they've gone pretty well. The site is a .NET MVC 2 site that was

Host WCF in MVC2 Site

梦想与她 提交于 2019-11-27 15:49:37
We've got a very large, complex MVC2 website. We want to add an API for some internal tools and decided to use WCF. Ideally, we want MVC itself to host the WCF service. Reasons include: Although there's multiple tiers to the application, some functionality we'd like in the API requires the website itself (e.g. formatting emails). We use TFS to auto-build (continuous integration) and deploy - The less we need to modify the build and release mechanism the better We use the Unity container and Inversion of Control throughout the application. Being part of the Website would allow us to re-use

MVC 2 - Passing enum to CheckBoxFor

可紊 提交于 2019-11-27 15:12:26
问题 Let's assume we have a model: public class Document { public string Name { get; set;} public List<DayOfWeek> WeekDays { get; set; } } Is it possible to render checkboxes that represent days of week for that model? I've searched the internet but did not find any solution. I mean it works whith CheckBoxFor(model=> model.SomeProperty) but it does not work if SomeProperty is List<DayOfWeek> . DayOfWeek here is an enumeration. Thanks in advance. 回答1: You can enumerate on the values of the enum and

MVC 2 vs MVC 3 custom validation attributes using DataAnnotationsModelValidatorProvider.RegisterAdapter

自作多情 提交于 2019-11-27 14:45:36
问题 I read on some post, but cant find it now that in MVC 3 it was not really needed to create a Validator, only the Attribute. Is this true? I do say I find it confusing that the attribute has the IClientValidatable on it. So what does the DataAnnotationsModelValidator class do if the annotation has the client side script name (IClientValidatable), and the ability to validate (ValidationAttribute IsValid)? It would be really nice if I didnt have to register the Attribute with the Validator in

Why mvc Html.HiddenFor does not render my field?

浪尽此生 提交于 2019-11-27 14:42:44
问题 I'm trying to do this simple thing <%= Html.HiddenFor(model => model.Id)%> the model is [HiddenInput(DisplayValue=true)] public int Id { get; set; } but i always get this rendered <input type="hidden" value="0" name="UserInfo.Id" id="UserInfo_Id"> i've check and the id is NOT 0.. ?! need some explanation here... Edit The problem seem's to be the post thing mentionned below. This is working <input type="hidden" value="<%= Html.AttributeEncode(Model.Id) %>" id="<%= Html.IdFor(model=>model.Id)%>

Set session variable in Application_BeginRequest

半世苍凉 提交于 2019-11-27 14:21:29
问题 I'm using ASP.NET MVC and I need to set a session variable at Application_BeginRequest . The problem is that at this point the object HttpContext.Current.Session is always null . protected void Application_BeginRequest(Object sender, EventArgs e) { if (HttpContext.Current.Session != null) { //this code is never executed, current session is always null HttpContext.Current.Session.Add("__MySessionVariable", new object()); } } 回答1: Try AcquireRequestState in Global.asax. Session is available in

Dynamic list of checkboxes and model binding

感情迁移 提交于 2019-11-27 14:09:26
问题 I'm trying to create a view that contains a list of checkboxes that is dynamically created from a database, and then retrieve the list of selected ones when the form is posted back. My EF model contains a class: public class ItemIWouldLikeACheckboxFor { public int Id { get; set; } public string Description { get; set; } } I have a view model that contains a list of these: public class PageViewModel { // various other properties public List<ItemIWouldLikeACheckboxFor> checkboxList { get; set;

ASP.NET MVC 2 loading partial view using jQuery - no client side validation

放肆的年华 提交于 2019-11-27 14:02:33
问题 I am using jQuery.load() to render a partial view. This part looks like this: $('#sizeAddHolder').load( '/MyController/MyAction', function () { ... }); The code for actions in my controller is the following: public ActionResult MyAction(byte id) { var model = new MyModel { ObjectProp1 = "Some text" }; return View(model); } [HttpPost] public ActionResult MyAction(byte id, FormCollection form) { // TODO: DB insert logic goes here var result = ...; return Json(result); } I am returning a partial