asp.net-mvc-2

MVC: How to post File Upload and other form fields to one action

独自空忆成欢 提交于 2019-11-27 18:08:50
I am creating a document library application with a DocumentController that needs to upload a thumbnail image of each doument in the library. I want to keep the File Upload field on the same Create/Edit form as the other fields (Title, Description, CategoryId etc). The problem is I'm not sure if I can mix or nest the form tags for Html.BeginForm("Create", "Document", FormMethod.Post, enctype = "multipart/form-data") and Html.BeginForm() My view is as follows: <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<Publications.WebUI.Models

The Purpose of a Service Layer and ASP.NET MVC 2

风流意气都作罢 提交于 2019-11-27 17:52:37
In an effort to understand MVC 2 and attempt to get my company to adopt it as a viable platform for future development, I have been doing a lot of reading lately. Having worked with ASP.NET pretty exclusively for the past few years, I had some catching up to do. Currently, I understand the repository pattern, models, controllers, data annotations, etc. But there is one thing that is keeping me from completely understanding enough to start work on a reference application. The first is the Service Layer Pattern. I have read many blog posts and questions here on Stack Overflow, but I still don't

Technique for carrying metadata to View Models with AutoMapper

北慕城南 提交于 2019-11-27 17:45:20
I use AutoMapper to map my domain objects to my view models. I have metadata in my domain layer, that I would like to carry over to the view layer and into ModelMetadata. (This metadata is not UI logic, but provides necessary information to my views). Right now, my solution is to use a separate MetadataProvider (independently of ASP.NET MVC), and use conventions to apply the relevant metadata to the ModelMetadata object via an AssociatedMetadataProvider. The problem with this approach is that I have to test for the same conventions when binding the ModelMetadata from the domain as I do with my

Visual Studio 2010 Local SSRS Report (.rdlc) with Object Data Source

孤街醉人 提交于 2019-11-27 17:21:11
问题 I've created more projects using ReportViewer 2005 and 2008 in local processing mode than I can count on my hands. All Visual Studio 2005 or 2008 ASP.NET web forms projects. I always used some flavor of Object data source for the reports. Tonight, I attempted to add the same functionality to a Visual Studio 2010 MVC 2 project and am failing miserably. First, the Add New Item > Reporting > Report is now a 2008 RDLC and not a 2005 RDLC report. Secondly, when trying to add a DataSet, my usual

Get [DisplayName] attribute of a property in strongly-typed way

白昼怎懂夜的黑 提交于 2019-11-27 17:20:38
Good day! I've such method to get [DisplayName] attribute value of a property (which is attached directly or using [MetadataType] attribute). I use it in rare cases where I need to get [DisplayName] in controller code. public static class MetaDataHelper { public static string GetDisplayName(Type dataType, string fieldName) { // First look into attributes on a type and it's parents DisplayNameAttribute attr; attr = (DisplayNameAttribute)dataType.GetProperty(fieldName).GetCustomAttributes(typeof(DisplayNameAttribute), true).SingleOrDefault(); // Look for [MetadataType] attribute in type

Can EditorFor() be used to create <input type=“file”>?

此生再无相见时 提交于 2019-11-27 17:15:06
问题 Given this model, is it possible to use the Html.EditorFor() to render a file upload input element to the page? I played around with the Datatype of the property FileName, and it was definitely impacting the editor form rendered. public class DR405Model { [DataType(DataType.Text)] public String TaxPayerId { get; set; } [DataType(DataType.Text)] public String ReturnYear { get; set; } public String FileName { get; set; } } Strongly Typed *.aspx page looks like this <div class="editor-field"> <%

Is asp.net MVC2 included in .net 4.0 framework?

丶灬走出姿态 提交于 2019-11-27 17:08:17
问题 I've installed .net 4 in the server. Now I don't know if I must install the MVC 2 for VS2008 or what because I got this error: Could not load file or assembly 'System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified. 回答1: VS 2010 comes with MVC 2, but it's not a part of the .NET Framework proper. This means that if you go download the .NET Framework 4 redistributable, it will not include the MVC 2

ASP.Net MVC2 Custom Templates Loading via Ajax and Model Updating

旧巷老猫 提交于 2019-11-27 17:02:01
问题 I have a view model with a collection of other objects in it. public ParentViewModel { public int Id { get; set; } public string Name { get; set; } public List<ChildViewModel> Child { get; set; } } public ChildViewModel { public int Id { get; set; } public string FirstName { get; set; } } In one of my views I pass in a ParentViewModel as the model, and then use <%: Html.EditorFor(x => x) %> Which display a form for the Id and Name properties. When the user clicks a button I call an action via

How to set a default value with Html.TextBoxFor?

会有一股神秘感。 提交于 2019-11-27 16:58:34
Simple question, if you use the Html Helper from ASP.NET MVC Framework 1 it is easy to set a default value on a textbox because there is an overload Html.TextBox(string name, object value) . When I tried using the Html.TextBoxFor method, my first guess was to try the following which did not work: <%: Html.TextBoxFor(x => x.Age, new { value = "0"}) %> Should I just stick with Html.TextBox(string, object) for now? you can try this <%= Html.TextBoxFor(x => x.Age, new { @Value = "0"}) %> This should work for MVC3 & MVC4 @Html.TextBoxFor(m => m.Age, new { @Value = "12" }) If you want it to be a

Unit tests on MVC validation

烂漫一生 提交于 2019-11-27 16:53:34
How can I test that my controller action is putting the correct errors in the ModelState when validating an entity, when I'm using DataAnnotation validation in MVC 2 Preview 1? Some code to illustrate. First, the action: [HttpPost] public ActionResult Index(BlogPost b) { if(ModelState.IsValid) { _blogService.Insert(b); return(View("Success", b)); } return View(b); } And here's a failing unit test that I think should be passing but isn't (using MbUnit & Moq): [Test] public void When_processing_invalid_post_HomeControllerModelState_should_have_at_least_one_error() { // arrange var mockRepository