asp.net-mvc-2

ASP.NET MVC 2 - Html.DropDownListFor confusion with ViewModel

亡梦爱人 提交于 2019-11-28 18:42:07
问题 I'm getting totally lost and confused on how to use the new strongly typed Html.DropDownListFor helper on ASP.NET MVC 2.0 R2 In the View I'm writting: <%= Html.DropDownListFor(m => m.ParentCategory, new SelectList(Model.Categories, "CategoryId", "Name", Model.ParentCategory), "[ None ]")%> <%= Html.ValidationMessageFor(m => m.ParentCategory)%> and my Model object is thus: public class CategoryForm : FormModelBase { public CategoryForm() { Categories = new List<Category>(); Categories.Add(new

Percentage calculation

寵の児 提交于 2019-11-28 18:32:26
I am working in progress bar concept in ASP.NET MVC 2. Here i have a DropDownList which has 10 values. i want to calculate the percentage for progress bar, e.g. 10 values from DropDownList and i am having a query which returns the value 2. so, out of 10 values i am getting 2. "20 % completed" should be displayed.. How to do this calculation (current / maximum) * 100 . In your case, (2 / 10) * 100 . Sogger Using Math.Round() : int percentComplete = (int)Math.Round((double)(100 * complete) / total); or manually rounding: int percentComplete = (int)(0.5f + ((100f * complete) / total)); With C#

How to concatenate several MvcHtmlString instances

ぃ、小莉子 提交于 2019-11-28 18:31:05
I have some doubts about how to concatenate MvcHtmlString instances because of this information found in MSDN : MvcHtmlString Class Represents an HTML-encoded string that should not be encoded again Do I risk that strings are HTML-encoded twice when using code like this: var label = Html.LabelFor(model => model.Email); var textbox = Html.TextBoxFor(model => model.Email); var validation = Html.ValidationMessageFor(model => model.Email); var result = MvcHtmlString.Create( label.ToString() + textbox.ToString() + validation.ToString()); (note: this is supposed to go into an HtmlHelper extension

Asp.Net MVC 2 - Changing the PropertyValueRequired string

你说的曾经没有我的故事 提交于 2019-11-28 18:25:59
Using a resx file in the App_GlobalResources directory, I've been able to change the default message for the PropertyValueInvalid string of the model validators. But it doesn't work to translate the message when a value is required (PropertyValueRequired.) In the Global.asax.cs Application_Start() I've changed the resource class key, like this: DefaultModelBinder.ResourceClassKey = "Messages"; And in the Messages.resx files I've put two entries: "PropertyValueInvalid" => "O valor '{0}' é inválido para o campo {1}." "PropertyValueRequired" = > "É necessário digitar o {0}." Thanks.

Rendering the field name in an EditorTemplate (rendered through EditorFor())

不打扰是莪最后的温柔 提交于 2019-11-28 18:19:33
I'm currently building the Admin back-end for a website in ASP.NET MVC. In an ASP.NET MVC application, I've started using the 'EditorFor' helper method like so: <div id="content-edit" class="data-form"> <p> <%= Html.LabelFor(c => c.Title) %> <%= Html.TextBoxFor(c => c.Title)%> </p> <p> <%= Html.LabelFor(c => c.Biography) %> <%= Html.EditorFor(c => c. Biography)%> </p> </div> In the model, the 'Biography' field has been decorated with: [UIHelper("Html")]. I have an 'Html' partial view (under Views/Shared/EditorTemplates): <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<System

Multiproject areas in ASP.Net MVC 3

烂漫一生 提交于 2019-11-28 17:55:17
Does any one have any idea about multiproject area support in asp.net mvc 3? As it was degraded to future status in mvc 2. If it is still not included then should we look forward for ASP.Net MVC Portable Areas via MvcContrib . Can you share your expreriences? What are the recommended way for managing a large application? I read about MEF . In what scenarios MEF is recommended? I'm the development lead on ASP.NET MVC at Microsoft. There are no plans to include multi-project areas in ASP.NET MVC 3. However, it's definitely an area that we plan to revisit in the future. In the meantime MvcContrib

What is the difference between [AcceptVerbs(HttpVerbs.Post)] and [HttpPost]?

橙三吉。 提交于 2019-11-28 17:08:23
I can decorate an action either with the [AcceptVerbs(HttpVerbs.Post)]/[AcceptVerbs(HttpVerbs.Get)] [AcceptVerbs(HttpVerbs.Post)] public ActionResult Create(string title) { // Do Something... } or with the [HttpPost]/[HttpGet] attributes [HttpPost] public ActionResult Create(string title) { // Do Something... } Are they different? Nothing. One is just shorthand for the other. Rudresha Parameshappa [HttpPost] is shorthand for [AcceptVerbs(HttpVerbs.Post)] . The only difference is that you can't use [HttpGet, HttpPost] (and similar) together on the same action. If you want an action to respond

ASP.NET MVC: Is Data Annotation Validation Enough?

99封情书 提交于 2019-11-28 17:03:34
I'm using the Data Annotation validation extensively in ASP.NET MVC 2. This new feature has been a huge time saver, as I'm now able to define both client-side validation and server-side validation in one place. However, while I was doing some detailed testing, I realized that it's quite easy for someone to bypass the server-side validation if I relied on Data Annotation validation alone. For example, if I defined a required field by annotating the property with the [Required] attribute and placed a textbox for that required field in a form, a user could simply remove the textbox from the DOM

ASP.NET MVC2 - Custom Model Binder Examples

时光怂恿深爱的人放手 提交于 2019-11-28 16:51:32
问题 I am trying to find some examples of building a custom model binder for a unique binding scenario I need to handle, but all of the articles I found were for older versions of MVC which are no longer relevant in MVC2. I've been referencing the DefaultModelBinder source code to try to get a general feel for what I need to do, but it's entirely more complicated than my scenario and I'm having trouble isolating the specific logic I need to implement. My goal is to take a collection of Checkbox

Using cookie in asp.net mvc c#

倾然丶 夕夏残阳落幕 提交于 2019-11-28 15:59:53
I want to register the parameter of a few pages in my web site using cookie. I tried the below code but not like what I want : public ActionResult Index(int? dep, int? cat) { ...... string theDept = Request.QueryString["dep"]; HttpCookie cookie = new HttpCookie("search"); cookie.Values["dep_name"] = theDept; cookie.Expires = DateTime.Now.AddDays(1); Response.Cookies.Add(cookie); return View(); } I read it in site.master : <% HttpCookie cookie = Request.Cookies["search"] ; if ((cookie != null) && (cookie.Value != "")) { Response.Write(cookie.Values["dep_name"].ToString() + "---" + cookie.Values