asp.net-mvc-2

ASP.NET Mvc - nullable parameters and comma as separator

别来无恙 提交于 2019-12-06 12:48:52
How should I define route in my global.asax to be able use nullable parameters and coma as separator? I'm trying to implement routing rule for my search users page like "{Controller}/{Action},{name},{page},{status}" Full entry from the Global.asax: routes.MapRoute( "Search", "{controller}/{action},{name},{page},{status}", new { controller = "User", action = "Find", name = UrlParameter.Optional, page = UrlParameter.Optional, status = UrlParameter.Optional } ); Routine defined like above works fine when I'm entering all parameters, but when some parameters are equal to null routing fails (for

Silverlight, RIA Services, MVC2P2 = No Data

余生颓废 提交于 2019-12-06 12:43:59
I am having trouble upgrading my current project to use RIA Services. I added all the necessary web.config changes but still no luck. I everything compiles fine but when I hit the page using the datacontext I get an error. I debugged with fiddler and I'm getting a 404 on one of the request. I am getting back headers in my grid so some communication is happening but no data is actually coming through. Another thing to note is that my MVC is running windows authentication. I do have a clientaccesspolicy.xml as well. Error in Silverlight with Headers but no data, Response from Fiddler:

Can I pass the viewbag value to the jQuery in mvc2

大兔子大兔子 提交于 2019-12-06 12:04:29
I need to pass the value to jQuery in the view using viewbag. What I want to achieve is pass the null or some value and then jQuery should hide or show the div depending on the value passed for instance something like below: viewbag.testNumber = null; $('#showdiv').hide(); $('viewbag.testNumber').value == someinteger{ $("#showdiv").show(); else $("#showdiv").hide(); }); <div id="showdiv"> Some Calculation </div> Also I want to disable the viewbag in the view if the value is null , because it gives null error ViewBag is only in ASP.NET MVC 3 so you can't use that, but you can use ViewData: $('

Is IDataErrorInfo ignored during model validation in MVC 2?

非 Y 不嫁゛ 提交于 2019-12-06 11:56: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? 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, object value) { IDataErrorInfo model = bindingContext.Model as IDataErrorInfo; if (model != null) { string str

ASP.NET MVC: DropDownList validation

谁说胖子不能爱 提交于 2019-12-06 11:20:14
问题 Note: The following is just an example. I'm pretty new to ASP.NET MVC and I'm trying to get my head around how validation of dropdown lists work. I have the following property in my ProfileViewModel class: [DisplayName("Gender")] public bool? Gender { get; set; } null is meant to mean "unknown", true female and false male. In the view model constructor I AllGenders = new List<SelectListItem>(2) { new SelectListItem {Text = "Unknown", Value = "null"}, new SelectListItem {Text = "Male", Value =

ASP.NET MVC2: How to render a view if has multiple different models

笑着哭i 提交于 2019-12-06 11:13:59
问题 I know that view model can be used for rendering a view, but if a page needs different models, how can I pass them to the view? And how do I use them? 回答1: If you need to pass multiple models then create an all-encompassing model that has the smaller models hanging off as properties. For instance, let's say you are going to display a page for managing groups of users for your app. You would probably need to pass an IEnumerable<UserDisplayModel> and also an IEnumerable<GroupDisplayModel> to

Add a search box to a master page

折月煮酒 提交于 2019-12-06 10:35:52
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?? To summarize: Implement a search box in the MVC master page that directs to a different website and

step by step problem with validation on “back” button

十年热恋 提交于 2019-12-06 10:19:01
I have a 3 steps forms where I bind for each step on a ViewModel that has DataAnnotation. Everything works fine except that when I click on my "previous" button, the validation gets called and, if there's missing values, the user has to fill all required fields. If I go with an action link, then the data won't be persisted. What I'm looking for here is a way to save my values without calling the validation. I also consider using cookies but I don't think that it's the best way of doing it. Any ideas or suggestions? I use separate models for each step of my wizard pages. I also make sure that

Asp.Net MVC 2 Client validation implementation for Enterprise Library Validation Block

[亡魂溺海] 提交于 2019-12-06 10:14:33
I've found a very good article about how to use EntLib Validation Block for server validation in MVC 2. But as there pointed out The current design of EntLib’s Validation Application Block uses the Composite pattern; that is, when we ask for validation for an object, it returns back a single validator object that contains a list of all the validation work to be done. While this is very convenient from a normal usage scenario, the unfortunate side-effect is that we can’t “peek inside” to see what the individual validations are that it’s doing, and therefore can’t generate the appropriate client

Controller ambigous error, upgraded to MVC 2

女生的网名这么多〃 提交于 2019-12-06 09:57:24
问题 I upgraded to MVC 2, updated all my assemblies (did copy to local also). I changed my routes to this: routes.MapRoute( "Admin", "admin/{controller}/{action}/{id}", new { controller = "Admin", action = "index", id = ""}, new[] { "MyNamespace.Web.Controllers.Admin" } // namespace ); routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = "" }, // Parameter defaults new[] { "MyNamespace.Web.Controllers" } //