asp.net-mvc-2

PathTooLongException after migrating from ASP.NET MVC 1 to ASP.NET MVC 2

一世执手 提交于 2019-12-05 14:26:56
I had updated my app from MVC 1 to MVC 2. After that some pages throws PathTooLongException : [PathTooLongException: The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.] System.IO.Path.SafeSetStackPointerValue(Char* buffer, Int32 index, Char value) +7493057 System.IO.Path.NormalizePathFast(String path, Boolean fullCheck) +387 System.IO.Path.NormalizePath(String path, Boolean fullCheck) +36 System.IO.Path.GetFullPathInternal(String path) +21 System.Security.Util

Configuring ASP.NET MVC app's IIS 7.5 Application Pool identity as login on SQL Server 2008 R2

…衆ロ難τιáo~ 提交于 2019-12-05 14:15:23
I am trying to use IIS 7.5 Application Pool identity as login on SQL Server 2008 R2 so that my ASP.NET web app can connect to the database... Using this approach worked fine on my local dev machine (IIS 7.5 and SQL Server 2008 R2 on same machine). However, when I try to set up the same on production (IIS and SQL servers are separate) I am unable to add "IIS APPPOOL\MyAppAppPool" login to SQL Server 2008 R2. Notice that in either case you cannot use "Browse..." when creating a login in SQL Server since "IIS APPPOOL\MyAppAppPool" user identity is dynamic (or "special")... Any ideas? Update: For

MVC Dataannotation validation rule for a collection?

和自甴很熟 提交于 2019-12-05 13:34:31
Is there a dataannotation validate rule for a collection based property? I have the following <DisplayName("Category")> <Range(1, Integer.MaxValue, ErrorMessage:="Please select a category")> Property CategoryId As Integer <DisplayName("Technical Services")> Property TechnicalServices As List(Of Integer) I'm looking for a validator that i can add to the TechnicalServices property to set a minimum for the collection size. I think something like this might help: public class MinimumCollectionSizeAttribute : ValidationAttribute { private int _minSize; public MinimumCollectionSizeAttribute(int

How to use a ShortDate string format with Html.TextBoxFor

北城以北 提交于 2019-12-05 12:50:17
Using Entity Framework with MVC2, I have a series of date textboxes, that I want to display data from the model in a short date format, but I have to use Html.TextBoxFor in order for the update code to work (Having tried using HTML.Textbox the data never gets saved to the model). <%: Html.TextBoxFor(model => model.Item.Date, String.Format("{0:d}", Model.Item.Date))%> I've tried manipulating the string format expression, and have added metadata to a partial class mapped to the Entity Framework model class, however still I get the following populating my textboxes at form render: 01/01/2011 00

Read DataAnnotations from a collection of models in an MCV2 view

笑着哭i 提交于 2019-12-05 12:30:40
In my MVC2 AdminArea I'd like to create an overview table for each of my domain models. I am using DataAnnotations like the following for the properties of those domain model objects: [DisplayName("MyPropertyName")] public string Name { get; set; } Now my question is: How can I access the DisplayName Attribute if my view receives a collection of my domain models? I need this to build the table headers which are defined outside of the usual <% foreach (var item in Model) { %> loop. Inside this loop I can write <%: Html.LabelFor(c => item.Name) %> but is there any way to access this information

Why use Url.Content for referencing resources?

隐身守侯 提交于 2019-12-05 11:44:44
In almost every ASP.NET MVC example I've come across, I always see Url.Content being used to reference CSS, JavaScript, and Images. Not once has anyone explained WHY to use it. Anyone care to explain? What's so bad about doing: <img src="/Content/Img/MyImage.png" alt="My Image" /> <script src="/Scripts/jquery.js" type="text/javascript"></script> <link href="/Content/Css/Default.css" rel="stylesheet" type="text/css" media="all" /> What you have works the same as Url.Content(). Url.Content() is just like adding a ~ to be beginning of your paths: <script src="~/Scripts/jquery.js" type="text

Html.ActionLink with id value from a dropdownlist

假装没事ソ 提交于 2019-12-05 10:30:48
I've got a dropdownlist: <%= Html.DropDownList("ddlNames", new SelectList(Model.NameList, "ID", "Name"))%> I've got an ActionLink: <%: Html.ActionLink("edit", "Edit", "Members", new { area = "MembersArea", id = XXX }, null)%> I want the value of the dropdownlist in the XXX. So I want to use values from controls on a view in the ActionLink. Is that possible in a simple manner? thanks, Filip You can't do this because the html helpers execute at the server side while the dropdown value can change at the client side. The only way to achieve it is to use javascript. You could register for the

ambiguous reference

人走茶凉 提交于 2019-12-05 10:06:26
问题 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

How to change returned ContentType in ASP.NET MVC controller (ActionResult)

£可爱£侵袭症+ 提交于 2019-12-05 09:47:30
问题 I have ASP.NET MVC controller named dictionary with method ControlsLangJsFile. Method returns view of users control (ASCX) which contain JavaScript variables. When i call the method it returns variables with parsed strings, but Content Type is html/text. It should be: application/x-javascript public ActionResult ControlsLangJsFile() { return View("~/Views/Dictionary/ControlsLangJsFile.ascx",); } How do i achieve this? 回答1: Users control doesn't accept ContentType="text/xml" Solution: public

How should I return an Image from a controller action c# asp.net-mvc-2?

笑着哭i 提交于 2019-12-05 09:41:06
I am building images from a byte[] like below. public FileContentResult GetEmployeeImage(int empId) { MemoryStream ms = new MemoryStream(byteArray); Image returnImage = Image.FromStream(ms); return returnImage;//How should i return this image to be consumed by javascript. } I want to return this image to the browser via a controller action method, so as it can be consumed by my javascript code and displayed in the browser. How should I do this? You don't need to create an image object; you just want to return the raw data. The browser will read the raw data into an image. return File(byteArray