asp.net-mvc-2

HiddenInput(DisplayValue = false)] vs [ScaffoldColumn(false)]

人走茶凉 提交于 2019-12-04 02:20:34
What is Exaclty ScaffoldColumn(false) and HiddenInput(DisplayValue = false) ? And What are the main difference between these two ? Which one is best to use?? Thanks!!! [ScaffoldColumn(false)] tells Visual Studio not to scaffold the column when generating a template for your view. When you create a new view, you can create a strongly typed view. When you do that Visual Studio asks you what template to use (Create, Edit, List, etc). If you create an Edit/Create template; for example, if you put [ScaffoldColumn(false)] on your model property then it just won't generate a DisplayFor() or EditorFor

conditional either or validation in asp.net mvc2

一笑奈何 提交于 2019-12-04 02:11:24
问题 In my registration page I have land line phone number and mobile number fields. I need to ensure that the user needs to add at least one phone number either the land line or mobile. How do I do this? Thanks Arnab 回答1: You could write a custom validation attribute and decorate your model with it: [AttributeUsage(AttributeTargets.Class)] public class AtLeastOnePhoneAttribute: ValidationAttribute { public override bool IsValid(object value) { var model = value as SomeViewModel; if (model != null

How to change width of html.DropDownListFor()

浪尽此生 提交于 2019-12-04 01:46:13
I have small design question about html.DropDownListFor() How can I change width of html.DropDownListFor() ?? For example by css. Thanks for answers Have you tried Html.DropDownListFor( new {width:"100"}) or Html.DropDownListFor( new {@class:"longDropdownList"}) EDIT <style> .MakeWide { width: 200px; } </style> <%= Html.DropDownListFor(x => x.Name, new SelectList(new List<string>()), new { @class = "MakeWide" })%> @Html.DropDownListFor(x => x.Name, new SelectList(new List<string>()), new {style="width:270px;"} ); Will do the thing. Although better to use css class h.boulla In C# you need add @

hide columns dynamically in rdlc report

荒凉一梦 提交于 2019-12-04 01:40:17
How we can hide columns dynamically in rdlc reports in MVC 2? Is it is possible using external parameters? How we can programmatically control the visibility of columns in rdlc reports? You don't want to use the Hidden property, you actually want to select the column, Right Click and select Column Visibility . Once in here you can use an expression to set the visibility based on a parameter, something like this: = iif(Parameters!column_visible.Value = 1, false, true) Hidden doesn't work in this instance because you're not actually applying it to an object like you are when you select something

Asp.Net MVC EnableClientValidation doesn't work

£可爱£侵袭症+ 提交于 2019-12-03 23:51:19
问题 I want as well as Client Side Validation as Server Side Validation. I realized this as the following: Model: ( The model has a DataModel(dbml) which contains the Test class ) namespace MyProject.TestProject { [MetadataType(typeof(TestMetaData))] public partial class Test { } public class TestMetaData { [Required(ErrorMessage="Please enter a name.")] [StringLength(50)] public string Name { get; set; } } } Controller is nothing special. The View: <% Html.EnableClientValidation(); %> <% using

EF 4 with POCO in class library as MVC 2 model

眉间皱痕 提交于 2019-12-03 22:53:30
问题 I am exploring Entity Framework 4 with POCO as my Model for an MVC2 web app. The reason I'll need the model and data access code in a separate library is so I can share it with another web application that serves as a portal for our clients to access our data. My question is, will I lose any of the typical MVC2 Model features by having my EF4 and POCO code in another project? Or maybe another way to ask this is will the MVC framework be able to work with the Model layer just the same if it is

When do you use View() vs. RedirectToAction

▼魔方 西西 提交于 2019-12-03 22:36:12
This existing question sums up the basics of my question. The best answers there tells the difference between the two methods. I am looking for guidelines as to which method to use. In short, I have an action in a controller which process a form and then display the results of the processing. When should I use return View() as opposed to return RedirectToAction("FormResult") ? You can really use either. Generally speaking, though, after a form is posted you want to redirect so that refreshing the page doesn't cause the form to repost. Sometimes, however, it's not feasible to copy state to the

ambiguous reference

我怕爱的太早我们不能终老 提交于 2019-12-03 22:32:53
I removed a project in my solution and then later re-added it. Since reading it.. I'm getting an ambiguous reference error now which I can't remove. viewing the implementation of the class (which is getting the error) I see it references it twice: > ClassName (myclass.Class) myclass.Class > ClassName (myclass.Class) myclass.Class, Version=1.0.0.0 the namespace is only viewed once, but this problem only exists in 1 partial view. EDIT: <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<MyClass.Class.MyViewModel>" %> MyViewModel is giving the ambiguous error, if i view all the

ViewDataFactory and strongly typed master pages

余生长醉 提交于 2019-12-03 21:41:26
Im trying to get my strongly typed master page to work in my ASP MVC 2.0 application. I have come far with the help of these two posts: Passing data to Master Page in ASP.NET MVC Strongly Typed ASP.Net MVC Master Pages Problem is that im not sure how to get that ViewDataFactory code to work, this is my code: BaseController.cs public class BaseController : Controller { private IPageRepository _repPage; public BaseController(IPageRepository repPage) { _repPage = repPage; } protected T CreateViewData<T>() where T : MasterViewData, new() { IViewDataFactory factory = new ViewDataFactory();

In ASP.NET MVC 2 - How do I get Route Values into my navigation controller so I can highlight the current link?

南楼画角 提交于 2019-12-03 21:32:26
问题 I'm trying to get the current Route into my navigation controller so I can run comparisons as the navigation menu data is populated. My Links object is like this: public class StreamNavLinks { public string Text { get; set; } public RouteValueDictionary RouteValues { get; set; } public bool IsSelected { get; set; } } In the master page, I'm trying to pass the current route to the nav controller like this: <% Html.RenderAction( "MenuOfStreamEntries", // action "Nav", // controller new { //