asp.net-mvc-2

RedirectToAction outside of Areas

隐身守侯 提交于 2019-12-08 16:39:13
问题 I've recently updated our MVC 2 project at work to use Areas however I'm having a little problem with the RedirectToAction method. We still have some of our controllers etc outside of our Areas. These controllers include the Home controller etc. How do I do a RedirectToAction from inside an Area to a controller outside of Areas. I thought something like the following might work but doesn't: return RedirectToAction("Index", "Home", new { area = "" }); or return RedirectToAction("Index", "Home"

Textbox reverts to old value while Modelstate is valid on postback

荒凉一梦 提交于 2019-12-08 16:37:20
问题 Maybe I'm missing something but when I have a form that posts back to the same action, the textbox value reverts to the old value. The following example should increment the value in the textbox on each POST. This does not happen, the value on the model is incremented and the model is valid. IF however I clear the modelstate in the HttpPost Action (the comment in the code), everything works as expected. Am I missing something? Here's the code: Model: public class MyModel { public int MyData {

The type or namespace name 'Mvc' does not exist in the namespace 'System.Web'

◇◆丶佛笑我妖孽 提交于 2019-12-08 16:05:34
问题 After converting a Hybrid ASP.NET MVC1 app to MVC2 I'm getting the following error when I try and run the application: The type or namespace name 'Mvc' does not exist in the namespace 'System.Web' (are you missing an assembly reference?) The allegeded culprit in the web.config file is System.Web.Mvc: <namespaces> <add namespace="System.Web.Mvc"/> <add namespace="System.Web.Mvc.Ajax"/> <add namespace="System.Web.Mvc.Html"/> So far my investigation seems to lead me to believe that version 2 of

.net Regular Expression to match any kind of letter from any language

百般思念 提交于 2019-12-08 15:55:49
问题 Which regular expression can I use to match (allow) any kind of letter from any language I need to match any letter including any diacritics (e.g. á, ü, ñ, etc.) and exclude any kind of symbol (math symbols, currency signs, dingbats, box-drawing characters, etc.) and punctuation characters. I'm using asp.net MVC 2 with .net 4. I've tried this annotation in my view model: [RegularExpression(@"\p{L}*", ... and this one: [RegularExpression(@"\p{L}\p{M}*", ... but client side validation does not

What is the “Func<object> modelAccessor” parameter for in MVC's DataAnnotationsModelMetadataProvider?

五迷三道 提交于 2019-12-08 15:13:25
问题 It's one of the parameters supplied to the CreateMetadata method (which you override if extending metadata support). ModelMetadata CreateMetadata(IEnumerable<Attribute> attributes, Type containerType, Func<object> modelAccessor, <<--THIS ONE Type modelType, string propertyName) I had assumed that it allowed you to access the model object itself (e.g. for setting metadata based on model values), however when I try to use it to cast to my model object I just get null. Entity ent = (Entity

MVC map to nullable bool in model

社会主义新天地 提交于 2019-12-08 15:04:50
问题 With a view model containing the field: public bool? IsDefault { get; set; } I get an error when trying to map in the view: <%= Html.CheckBoxFor(model => model.IsDefault) %> Cannot implicitly convert type 'bool?' to 'bool'. An explicit conversion exists (are you missing a cast?) I've tried casting, and using .Value and neither worked. Note the behaviour I would like is that submitting the form should set IsDefault in the model to true or false. A value of null simply means that the model has

“Unable to start debugging” - VS2010 ASP.NET MVC 2

若如初见. 提交于 2019-12-08 14:38:33
问题 I can launch debug session only once with VS2010 and ASP.NET MVC2. When I end the first session and try to launch another I can see... "Unable to start debugging" - no other messages, I'm using Visual Studio Development Server instead of IIS, Windows 7 64-bit I can add that few days ago I was working on Windows XP and everything was fine. I've tried running as admin (I thought there are any privileges issues) - no result checked http://msdn.microsoft.com/en-us/library/dwesw3ee%28VS.71%29.aspx

jQuery: modify hidden form field value before submit

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-08 13:50:08
问题 I have the following code in a partial view (using Spark): <span id="selectCount">0</span> video(s) selected. <for each="var video in Model"> <div style="padding: 3px; margin:2px" class="video_choice" id="${video.YouTubeID}"> <span id="video_name">${video.Name}</span><br/> <for each="var thumb in video.Thumbnails"> <img src="${thumb}" /> </for> </div> </for> # using(Html.BeginForm("YouTubeVideos","Profile", FormMethod.Post, new { id = "youTubeForm" })) # { <input type="hidden" id="video_names

ASP.NET MVC 2 Numeric value validation

夙愿已清 提交于 2019-12-08 13:31:18
问题 I have this property on a class: public virtual decimal? Number { get; set; } When I'm using it on a form, MVC validates it automatically. If the user enters a letter, naturally an error is returned: "The value 'D' is not valid for Number." How do I change such error message or even control that behavior? I'm not finding the related attribute or something like that. Thank you! 回答1: It is actually not a message that derives from model validation. The message is added to the model state when

MVC 2 Entity Framework View Model Insert

落花浮王杯 提交于 2019-12-08 13:16:55
问题 This is driving me crazy. Hopefully my question makes sense... I'm using MVC 2 and Entity Framework 1 and am trying to insert a new record with two navigation properties. I have a SQL table, Categories, that has a lookup table CategoryTypes and another self-referencing lookup CategoryParent. EF makes two nav properties on my Category model, one called Parent and another called CategoryType, both instances of their respective models. On my view that creates the new Category, I have two