asp.net-mvc-2

asp.net request.form

时光总嘲笑我的痴心妄想 提交于 2019-12-06 01:47:21
public ActionResult DisplayCustomer() { Customer objCustomer = new Customer(); objCustomer.Id = Convert.ToInt16(Request.Form["Customerid"]); objCustomer.CustomerCode = Request.Form["code"]; objCustomer.Amount = Convert.ToDouble(Request.Form["amount"]); return View(objCustomer); } This is my action in controller(MVC 2 aspx): <form action="DisplayCustomer" method="post"> Customer id:- <input type="text" id="Customerid" /><br /> Customer Code:- <input type="text" id="code" /><br /> Customer amount:- <input type="text" id="amount" /><br /> <input type="submit" value="click here" /> </form> This is

ModelBindingContext ModelName

只谈情不闲聊 提交于 2019-12-06 01:02:43
Can anyone explain where the ModelName gets populated from? Looked in MSDN documentation and no explaination here. I am creating a custom model binder and within it I get null for the following: var result = bindingContext.ModelName); The ModelBindingContext object is created and populated by whoever calls into the BindModel() method. If the model is coming in as an argument to your action method, this is done by ControllerActionInvoker.GetParameterValue(), and the ModelName property will be set to the name of the parameter (unless overridden by [Bind(Prefix = ... )]). If the model is being

ASP.NET MVC2 Model Validation Fails with Non-US Date Format

痞子三分冷 提交于 2019-12-06 00:44:43
问题 I have a small MVC2 app that displays in two cultures: en-US and es-MX. One portion contains a user input for a date that is pre-populated with the current date in the Model. When using en-US, the date field is displayed as MM/dd/yyyy and can be changed using the same format without causing any validation errors. When using es-MX, the date field is displayed as dd/MM/yyyy, but when the date is edited in this format, the server-side validation fails with the message: The value '17/05/1991' is

What's the difference between the database inside App_Data folder vs connecting to SQL Server?

与世无争的帅哥 提交于 2019-12-06 00:33:37
问题 I'm new to .NET and while starting to learn ASP .NET MVC2 framework I see that you can create a .mdf file inside the App_Data folder and connect to it or you can connect to a SQL Server. What is the difference between these to methods of interacting with a database? What are the advantages/disadvantages of one over the other? 回答1: The "MDF in the App_Data" folder works for web site and web apps, and it works only with SQL Server Express (2005, 2008, 2008 R2). This is the version that's

ASP.NET MVC 2 - Implementing custom Metadata and Validator Providers

自作多情 提交于 2019-12-06 00:27:34
With the preview 2 release of ASP.NET MVC 2 , we now have base classes to implement our own custom providers for metadata and validation. Specifically, with ModelMetadataProvider and ModelValidatorProvider . There isn't a lot of documentation on these yet (just released yesterday as a preview , so I'm neither surprised nor disappointed). Has anyone gotten custom implementations of either of these working? A very simple example (metadata and validator for just "Required") would be great! Perhaps a lot of people have the same idea, but I'd like to use IronRuby to inject the metadata, and I'm

Asp.Net MVC : Execution of the child request failed. Please examine the InnerException for more information

爱⌒轻易说出口 提交于 2019-12-06 00:13:33
问题 I'm recieving the following error message, A public action method 'RenderMenu' was not found on controller 'Web.Controllers.SiteController'. However this action DOES exist and the controller does exist (As it work everywhere on the site) I looked at the inner exception. Execution of the child request failed. Please examine the InnerException for more information. (This is the inner exception...) Stack Trace at System.Web.Mvc.HttpHandlerUtil.ServerExecuteHttpHandlerWrapper.Wrap[TResult](Func`1

attribute asks user to login instead of access denied?

微笑、不失礼 提交于 2019-12-05 23:11:20
问题 Updated: Thanks to the help here I've created the following solution: public class CustomAuthorize : AuthorizeAttribute { protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext) { // Returns HTTP 401 - see comment in HttpUnauthorizedResult.cs // If user is not logged in prompt if (!filterContext.HttpContext.User.Identity.IsAuthenticated) { base.HandleUnauthorizedRequest(filterContext); } // Otherwise deny access else { filterContext.Result = new

Overriding the default 'No Data' Message in MVCContrib Grid

自古美人都是妖i 提交于 2019-12-05 22:52:57
Is it possible to override the default 'There is no Data available' message in MVCContrib Grid with a custom message? <%= Html.Grid<SomeModelType>(Model) .Empty("Some custom message") ... %> 来源: https://stackoverflow.com/questions/3986528/overriding-the-default-no-data-message-in-mvccontrib-grid

asp.net mvc modifying master file from a view

依然范特西╮ 提交于 2019-12-05 22:13:38
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? 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 this and add it if it exists: <% string bodyClass = ""; if (ViewData["MasterPageBodyClass"] != null) {

ASP.NET MVC 2 Parameter Array

独自空忆成欢 提交于 2019-12-05 22:08:32
问题 I need to have the following routing logic: http://mydomain.com/myAction/{root}/{child1}/{child2}/... I don't know what is the depth of the route so I want the action's signature to look something like that: public ActionResult myAction(string[] hierarchy) { ... } Have no idea how to write that route. Help? Thanks a lot. 回答1: When you add the following mapping: routes.MapRoute("hierarchy", "{action}/{*url}" new { controller = "Home", action = "Index" }); you can obtain the string 'url' in