asp.net-mvc-2

Error “The view at '~/Views/Page/home.aspx' must derive from ViewPage, ViewPage<TViewData>, ViewUserControl, or ViewUserControl<TViewData>”

你说的曾经没有我的故事 提交于 2019-11-27 21:21:10
I've just installed MVC2 and I've got a view that looks like this <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Home.Master" Inherits="System.Web.Mvc.ViewPage" %> <asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"> Home </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> <h2>Home</h2> </asp:Content> And the controller is just returning the view. But when I run the page I get this error: System.InvalidOperationException: The view at '~/Views/Page/home.aspx' must derive from ViewPage, ViewPage, ViewUserControl,

Why does ASP.NET MVC care about my read only properties during databinding?

☆樱花仙子☆ 提交于 2019-11-27 21:15:57
Edit: Added bounty because I'm seeking an MVC3 solution (if one exists) other than this: DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false; I have a read only property on my 'Address' model 'CityStateZip' . It's just a convenient way to get city, state, zip from a US address. It throws an exception if the country is not USA (the caller is supposed to check first). public string CityStateZip { get { if (IsUSA == false) { throw new ApplicationException("CityStateZip not valid for international addresses!"); } return (City + ", " + StateCd + " " + ZipOrPostal

TextBoxFor rendering to HTML with prefix on the ID attribute

人盡茶涼 提交于 2019-11-27 20:52:07
I have an ASPNET MVC 2 project. When I use <%= Html.TextBoxFor(model => model.Login) %> the TexBoxFor will render as <input id="Login" name="Login" type="text" value="" /> Field in the model is [Required(ErrorMessage = "")] [DisplayName("Login")] public string Login { get; set; } Can I made id and name attribute with some prefix? Like <input id="prefixLogin" name="prefixLogin" type="text" value="" /> Thanks to all. It seems MVC 2 RTM does not currently provide this feature. You can try these extension methods: public static MvcHtmlString ValidationMessageFor<TModel, TProperty>(this HtmlHelper

How do I clear MVC client side validation errors when a cancel button is clicked when a user has invalidated a form?

只愿长相守 提交于 2019-11-27 20:26:51
I have a partial view that is rendered within a main view. The partial view takes advantage of System.ComponentModel.DataAnnotations and Html.EnableClientValidation() . A link is clicked, and div containing the partial view is displayed within a JQuery.Dialog() . I then click the save button without entering any text in my validated input field. This causes the client side validation to fire as expected, and display the '*required' message beside the invalid field. When the cancel button is clicked, I want to reset the client side MVC validation back to it's default state and remove any

mvc: does the favicon.ico also look for a controller?

喜欢而已 提交于 2019-11-27 20:21:00
I get an error: "The controller for path '/favicon.ico' was not found or does not implement IController" Then I thought: how does the framework know for which files it has to instantiate a controller, because the same thing is true for script, css and other files? (never thought of that, but now the favicon is complaining, I was wondering....) But back to the error, why does that occur? Steve Add this to you global.asax : routes.IgnoreRoute("favicon.ico"); You can also specify the ignore route with constraints routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" }); The

MVC2 Routing with WCF ServiceRoute: Html.ActionLink rendering incorrect links!

折月煮酒 提交于 2019-11-27 19:43:41
I have a WCF service that lives side-by-side with an MVC2 web site. I'd like for my URL for the service to look like this: http://localhost/projdir/Service The MVC site is in its infancy so it still has all its boilerplate controllers etc. The following code works at first glance in global.asax: public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.Add(new ServiceRoute("Service", new ServiceHostFactory(), typeof(MyService))); routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new {

UIHint Attribute in MVC

不想你离开。 提交于 2019-11-27 19:23:50
What is Use of UIHint Attribute in MVC . Can anyone please provide me a simple example of how to use it and what it does. When using a Display or Editor template, UIHint will tell it which template to use: [UIHint("SomeTemplate")] public class MyViewModel { public string SomeProperty { get; set; } } If you create a Display template called SomeTemplate.ascx (since you are MVC2) in the Views/Shared/DisplayTemplates or Views/{Controller}/DisplayTemplates then it will use that template when you do: @Html.DisplayForModel() // if Model is MyViewModel or @Html.DisplayFor(m => m.ModelProperty) // if

Implementing a Progress bar for long running task implemented with an ASP.NET MVC 2 AsyncController

最后都变了- 提交于 2019-11-27 19:08:51
After reading the documentation on AsyncControllers in ASP.NET MVC 2, I am wondering what's the best way to implement an ajax progress bar in this scenario. It seems a bit odd that the tutorial does not cover this at all. I guess implementing an AJAX progress bar involves requires additional action method that returns the status of the current task. However, I am not sure about the best way to exchange information on the status of the task between worker threads and that action method. My best idea so far was to put information on the curent progress into the Session dictionary along with a

How to validate two properties with ASP.NET MVC 2

本秂侑毒 提交于 2019-11-27 18:36:23
问题 I'm just getting started with ASP.NET MVC 2, and playing around with Validation. Let's say I have 2 properties: Password1 Password2 And I want to require that they are both filled in, and require that both are the same before the model is valid. I have a simple class called "NewUser". How would I implement that? I've read about ValidationAttribute, and understand that. But I don't see how I would use that to implement a validation that compares two or more properties against eathother. Thanks

An ASP.NET MVC validator to make sure at least one checkbox is checked

爷,独闯天下 提交于 2019-11-27 18:22:48
问题 I have an ASP.NET MVC 2 project in which I've created a data transfer object to receive data from a web page form. The form has two groups of checkboxes on it. I want to validate the object to make sure that at least one of the checkboxes in each group is checked. I'm doing the validation on the server side so that a user won't be able to hack around any client-side validation. (I will add client-side validation with jQuery later; that's easy.) My understanding is that I have to create my own