asp.net-mvc-2

Property-level validation errors hinder the validation of Class-level validation

余生颓废 提交于 2019-11-28 00:57:55
问题 Update after Bounty was awarded A new solution is coming up to this problem. Please refer to ASP.NET MVC 3 Preview 1 here: http://weblogs.asp.net/scottgu/archive/2010/07/27/introducing-asp-net-mvc-3-preview-1.aspx Look in the section Model Validation Improvements , where you will see the solution to my problem. Original Post Referring to my earlier post How to validate two properties with ASP.NET MVC 2 where I asked how I could compare two properties for Model validation. I did find the

Is it possible to use DisplayFor() from within the EditorFor template control

心不动则不痛 提交于 2019-11-28 00:57:00
问题 I am using EditorFor() helper to render edit template in my view and I would like to call the DisplayFor() inside this template to render out the Display template. Like this this is inside the /Shared/EditorTemplates/Client.ascx <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<BusinessNext.Models.Ef.Client>" %> <%: Html.DisplayFor(client=>client) %> In the DisplayFor template I render out client's properties. DisplayFor template works perfectly fine when called from

DropDownListFor not binding on Edit View with repeating items (List<T>)

自作多情 提交于 2019-11-27 23:52:41
Here is the thing. I have an Edit view, which doesnt bind the dropdowns' value when I open it. [NonAction] public List<SelectListItem> VraagType() { List<SelectListItem> l = new List<SelectListItem>(); SelectListItem a = new SelectListItem(); SelectListItem b = new SelectListItem(); a.Text = "Meerkeuze"; a.Value = "M"; b.Text = "Open"; b.Value = "O"; l.Add(a); l.Add(b); return l; } [NonAction] public List<SelectListItem> getSchalen() { return _db.EvalSchaals.ToList().ToSelectList(q => q.Sch_Naam, q => q.Sch_ID.ToString(), q => q.Sch_ID == -1).ToList(); } public ActionResult Edit(int id) {

ASP.NET MVC RequireHttps

白昼怎懂夜的黑 提交于 2019-11-27 23:41:17
How do I use the ASP.NET MVC 2 Preview 2 Futures RequireHttps attribute? I want to prevent unsecured HTTP requests from being sent to an action method. I want to automatically redirect to HTTPS. MSDN: RequireHttpsAttribute RequireHttpsAttribute Members RequireHttpsAttribute.HandleNonHttpsRequest Method How do I use this feature? My guess: [RequireHttps] //apply to all actions in controller public class SomeController { //... or ... [RequireHttps] //apply to this action only public ActionResult SomeAction() { } } I think you're going to need to roll your own ActionFilterAttribute for that.

Why am I getting ::1 as IP address in ASP.Net.. and how to get the proper IP address?

旧城冷巷雨未停 提交于 2019-11-27 23:20:29
问题 I am running an ASp.Net MVC app in the localhost - dev server given with a visual studio. I want to get the IP address. I tried Request.UserHostAddress and Request.ServerVariables("REMOTE_ADDR") In both cases, I am getting::1 as a result. What is it? Why am I getting it? How can I get 127.0.0.1 or 192.168.1.xxx? 回答1: You are getting a valid IP Address. ::1 is local_host in IPv6. (underscore used in local_host to stop SO from thinking it was some sort of bad text) 回答2: What you're seeing when

Getting 404 error on MVC web-site

社会主义新天地 提交于 2019-11-27 22:59:10
I have an IIS7.5 web-site, on Windows Server 2008, with an ASP.NET MVC2 web-site deployed to it. The website was built in Visual Studio 2008, targeting .NET 3.5, and IIS 5.1 has been successfully configured to run it as well, for local testing. However, whenever I try and navigate to a page running in IIS7, I get a 404 error. I have checked the following things: There is no corresponding 404 log entry in IIS logs. Actually, there are 404 entries in the IIS log. The application pool for the web-site is set to use the Integrated pipeline. The "customErrors" mode is set to off. .NET 3.5 SP1 is

Validating required selection in DropDownList

心不动则不痛 提交于 2019-11-27 22:48:41
My view model defines property which has to be displayed as combo box. Property definition is: [Required] public int Processor { get; set; } I'm using DropDownListFor to render combo box: <%=Html.DropDownListFor(r => r.Processor, Model.Processors, Model.Processor)%> Model.Processors contains IEnumerable<SelectListItem> with one special item defined as: var noSelection = new SelectListItem { Text = String.Empty, Value = "0" }; Now I need to add validation to my combo box so that user must select different value then 'noSelection'. I hoped for some configuration of RequiredAttribute but it doesn

The file “~/Views/Position/Edit.cshtml” cannot be requested directly because it calls the “RenderSection” method

拥有回忆 提交于 2019-11-27 21:50:15
I am trying to separate all the things that I could reuse in sections, so it would be easier for me to maintain. However I got this exception: The file "~/Views/Position/Edit.cshtml" cannot be requested directly because it calls the "RenderSection" method I created a file called sections.cshtml with the following content: @section scripts{ <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script> <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script> } And in the _layout.cshtml file I changed it to:

How to pass additional postdata into an add record function - JQGrid - MVC . NET

情到浓时终转凉″ 提交于 2019-11-27 21:42:48
I am using the JQGrid plugin on an MVC project. I am trying to avoid using 'Session'. I have been able to pass extra postdata into my edit and delete functions, using the serializedata methods from JQGrid. E.G. serializeEditData: function (postdata) { var rowdata = jQuery('#gridId').getRowData(postdata.id); return {id: postdata.id, oper: postdata.oper, SomeExtraData: $('#extradata').val()}; } However, there doesn't appear to be a serializeAddData function. Is there another way to alter the post data for the add method before it is sent? Oleg There are one method editGridRow which implement

Why is CheckBoxFor producing runtime error

不想你离开。 提交于 2019-11-27 21:22:46
问题 The field the CheckBox is wired to is nullable. On my view I get the following error: Cannot implicitly convert type 'bool?' to 'bool' <%= Html.CheckBoxFor(model => model.Product.Exclusive) %> How do I fix it without having to change the database design? 回答1: Exclusive cannot be Nullable, it makes no sense to the ViewEngine when evaluating the expression. It has to either check or not check the checkbox and also respond with a true or false value. Your model needs to have a bool value but