asp.net-mvc-2

Bind /action/1,2,3 to List<int>

半腔热情 提交于 2019-12-10 11:09:18
问题 In my API, I'd like to have routes like GET /api/v1/widgets/1,2,3 and GET /api/v1/widgets/best-widget,major-widget,bob-the-widget public class WidgetsController : MyApiController { public ActionResult Show(IEnumerable<int> ids) { } public ActionResult Show(IEnumerable<string> names) { } } I've got routes set up to get me to the action, but I can't figure out how to turn 1,2,3 into new List<int>(){1, 2, 3} and so on. Of course, I could just take a string and parse it in my action, but I'd like

Entity Framework 4 CTP 4 Code First: how to work with unconventional primary and foreign key names

孤人 提交于 2019-12-10 10:56:25
问题 Is there a way in Entity Framework 4 (using CTP4 and Code First if that matters) to change the conventions used to automatically identify primary and foreign keys? I'm trying to use EF with a legacy database that uses a "pk/fk" prefix rather than an "id" suffix to mark keys. Also, it's not uncommon to have multiple foreign keys to an Address table, for example, called "fkAddressHome" and "fkAddressWork". I would prefer a method for changing this behavior in a systematic way so that I don't

Add a search box to a master page

♀尐吖头ヾ 提交于 2019-12-10 10:53:46
问题 I'm trying to add a search box to a master page in an ASP.Net MVC web app. What's confusing me is how to properly implement it in the master page. So the user types in data into this search box, how should the data be handled from an MVC perspective?? I know I could use he master page's code behind, but I shouldn't. I'm currently trying to use a user control for this, but I'm not sure how to properly implement it and online resources seem to be limited. Would creating an HTML helper be best??

Is MVC2 ASP.Net URLDecoding automatically?

我的未来我决定 提交于 2019-12-10 10:50:54
问题 So I was calling the Controller in MVC2 like this and I accessed the classic querystrings just fine. Please notice that the second parameter thing2 is URLEncoded already and again retrieving the URLEncoded querystring and URLDecoding is no problem. My example looks like this... http://mydomain.com/controller?thing1=1544&thing2=somethingURLEncoded Now I try to move to the MVC2 ASP.Net way of handling parameters and make myself a nice custom MapRoute. I test it to see that it works with a

Custom ViewModel not displaying values in TextBoxFor TextBoxFor(Model => Model.Object1.Name)

前提是你 提交于 2019-12-10 10:44:40
问题 I have a custom Model, which contains another custom object (Objects1.Object2), I am correctly populating the object prior to display in the view and <%: Model.Object1.Name %> displays the data correctly yet <%: Html.TextBoxFor(model => model.Object1.Name) %> displays no data. I am new to MVC and would love to get around this issue as it is a stopping point to creating custom data model. Any info is greatly appreciated. 回答1: Are you trying to modify this in a POST action? If you are then note

Is IDataErrorInfo ignored during model validation in MVC 2?

时光毁灭记忆、已成空白 提交于 2019-12-10 10:44:10
问题 I currently migrated my project to MVC 2 and IDataErrorInfo doesn't seem to work when using default model binding and validation. Is it cut out? 回答1: SUMMARY I posted this error to MVC 2 issue tracker: http://aspnet.codeplex.com/WorkItem/View.aspx?WorkItemId=4891 It will be resolved in next preview release. DefaultModelBinder in MVC 1.0: protected virtual void OnPropertyValidated(ControllerContext controllerContext, ModelBindingContext bindingContext, PropertyDescriptor propertyDescriptor,

Asp.net mvc 2 templates without prefix

痴心易碎 提交于 2019-12-10 10:37:11
问题 Given following view model: class DetailsViewModel { public HeaderViewModel Header {get;set;} public FooterViewModel Footer {get;set;} } I'm using editor template for Header view model: <%: Html.EditorFor(x => x.Header) %> The editor template (EditorTemplates/HeaderViewModel.ascx) <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<HeaderViewModel>" %> <% ViewData.TemplateInfo.HtmlFieldPrefix = ""; %> <%: Html.EditorFor(x => x.Search) %> The result: <input type="text" value=""

asp.net mvc modifying master file from a view

左心房为你撑大大i 提交于 2019-12-10 10:31:30
问题 I need to add class attribute to the body tag from a view file (.aspx), but the tag is in the master file. How can I access the body tag from a view? 回答1: In your view output you could just add a jQuery client script to do it which will run once your page is pieced together: $('body').addClass('yourClass'); Another method would be to store the class data in your controller like: ViewData["MasterPageBodyClass"] = "yourClass"; Then in your MasterPage view you could check for the existance of

Can I add MVC 2 DataAnnotation attributes to existing properties?

时光总嘲笑我的痴心妄想 提交于 2019-12-10 10:26:39
问题 I'm using a generated class as a model, and I wish to add DataAnnotation attributes to some of its properties. As it's a generated code, I don't want to add the annotations directly. Is there another way to attach them to a property? I'd considered making the model an interface, and using a partial class to get the generated class to subscribe to it. Is there a less elaborate solution, assuming that would even work? 回答1: Yes there is. You have to create metadata class that will have the same

Overriding the default 'No Data' Message in MVCContrib Grid

岁酱吖の 提交于 2019-12-10 10:19:42
问题 Is it possible to override the default 'There is no Data available' message in MVCContrib Grid with a custom message? 回答1: <%= Html.Grid<SomeModelType>(Model) .Empty("Some custom message") ... %> 来源: https://stackoverflow.com/questions/3986528/overriding-the-default-no-data-message-in-mvccontrib-grid