asp.net-mvc-2

The value for a object inside a viewmodel lost on redirect to action in asp.net mvc 2.0?

。_饼干妹妹 提交于 2019-12-25 04:39:08
问题 I have a view model - public class MyViewModel { public int id{get;set;}; Public SomeClass obj{get;set;}; } public class SomeClass { public int phone{get;set;}; public int zip{get;set;}; } So on my controller when I post back MyViewModel it has all the values for all the fields...but when I do return RedirectoAction("SomeAction",vm);//where vm->MyViewModel object that has all values... it loses the values for SomeClass object?...can anyone please help me out 回答1: The second argument to

How to show dropdownlist value on edit

有些话、适合烂在心里 提交于 2019-12-25 04:19:34
问题 this is my Question extension to this Question.. Here I am able to add the Dropdown list value to the Grid.. perfectly.. Ex: in my Dropdownlist box I have A B C D items.. When I add any Item I am displaying the grid and I am reloading my page. My grid have two columns one is added Dropdownlist value.. other is some other text value.. each row in my grid have Edit button.. When I click Edit I am reloading my page to edit this selected dropdownlist value.. when I click Edit I need to show what

How to add a new validation rule to mvcClientValidationMetadata?

余生颓废 提交于 2019-12-25 04:16:31
问题 I have a form with two fields that need to be equal (password and password confirmation). I've created a class attribute to check that and on server side it works great. On the client side it does nothing. I need the message to appear in ValidationSummary ("Password repeated" needs to be the same as "Password"). I realized that the easiest way to check these fields would be adding the rule manually to window.mvcClientValidationMetadata. I was trying to do that but nothing worked. My code: <%

Problem saving new records to multiple tables from a single view

眉间皱痕 提交于 2019-12-25 03:45:31
问题 I am trying to add new records in my DB to multiple related tables that all have an ID as PK and IDs of other tables as FKs. I've based my approach on the NerdDinner tutorial but I can't find any examples on how to add new records in the DB when more than one table is involved. ModelState.IsValid fails when trying to save the new records for some reason. I tried adding them as shown below and update each table seperately but that doesn't work. I am new to MVC, .NET and programming in general

ASP.Net MVC2 - Set ViewModel values with retrieved from db object's values with DataAnnotations

一世执手 提交于 2019-12-25 03:27:54
问题 Prior to using a ViewModel, I could easily pass the "soon to be edited" object directly to the view without needing to fuss over setting individual properties etc as the View conveniently accepted the Employee type directly.. [HttpGet] public ActionResult EditEmployee(int? id) { EmployeeRepository ER = new EmployeeRepository(); Employee SomeEmployee = ER.GetEmployee(id.Value); if(SomeEmployee!=null) return View(SomeEmployee); But now I'm using a ViewModel with DataAnnotations attributes

Confusion over MVC and entity model

本小妞迷上赌 提交于 2019-12-25 03:13:28
问题 My confusion stems from the fact I am using 2 different walkthroughs on building mvc applications, namely: Steven Sanderson's pro asp.net mvc and the online mvc music store. The former creates a domain model, placing the entity model in there along with repositories, while the music store demo places the entity model in the mvc model folder. Which of these is the best approach. Should the entity model and associated repositories exist in a separate domain layer, or in the MVCs model folder.

Why do nested forms in Asp.net mvc not have scope?

余生颓废 提交于 2019-12-25 03:12:02
问题 I have form that has several forms inside of it in asp.net mvc. The nested forms are using ajax helpers and are ajax forms. The forms that are nested ALWAYS post to the original form's action, not their action. Why? Why can't I have multiple forms on one page? 回答1: You can have as many forms you like on a page, but you can't nest them. It has nothing to do with ASP.NET or MVC, it's the HTML form tag that doesn't allow nesting. If you try to nest forms, the browser will ignore the inner form

MVC Testing using a mocking framework (Moq)

感情迁移 提交于 2019-12-25 02:50:31
问题 I'm using Moq to help in testing my ASP.NET MVC2 application. Problem: ArgumentException was unhandled by user code. Unable to obtain public key for StrongNameKeyPair This code has been adapted from Scott Hanselman's NerdDinner1. HomeController CreateHomeControllerAs(string userName) { var mock = new Mock<ControllerContext>(); mock.SetupGet(p => p.HttpContext.User.Identity.Name).Returns(userName); // fails here mock.SetupGet(p => p.HttpContext.Request.IsAuthenticated).Returns(true); var

ASp.Net MVC routing

被刻印的时光 ゝ 提交于 2019-12-25 02:45:00
问题 I am using MVC 2.0 to create my application,my problem i s related to the routing. Actually in my application each user have required seperate subdomain,like www.example.com/user1/ ,www.example.com/user2/ ...etc.the default domain is www.example.com.So how can i make it possible with routing in mvc. i have tried like this, routes.Add(new Route( "{id}", new RouteValueDictionary( new { controller = "User", action = "login", id = " " } ), new MvcRouteHandler())); var defaults = new

Custom Validation on group of checkboxes

纵饮孤独 提交于 2019-12-25 02:22:51
问题 I'm trying to understand how I can validate a group of checkboxes. My Model: [MinSelected(MinSelected = 1)] public IList<CheckList> MealsServed { get; set; } I'd like to be able to create a custom validator that will ensure that at least 1 (or some other number) checkbox is selected. If not, display an ErrorMessage . #region Validators public class MinSelectedAttribute : ValidationAttribute { public int MinSelected { get; set; } // what do I need to do here? } Could someone help me out with