asp.net-mvc-2

Get DisplayName Attribute without using LabelFor Helper in asp.net MVC

百般思念 提交于 2019-12-17 07:08:38
问题 What is the best way to retrieve the display name attribute for an item in your model? I see a lot of people using the LabelFor helper for everything, but a label isn't appropriate if I just want to list the data out. Is there an easy way just get the Name Attribute if I just want to print it out in, say a paragraph? 回答1: <p> <%= Html.Encode( ModelMetadata.FromLambdaExpression<YourViewModel, string>( x => x.SomeProperty, ViewData).DisplayName ) %> <p> Obviously in order to avoid the spaghetti

Session state can only be used when enableSessionState is set to true either in a configuration

坚强是说给别人听的谎言 提交于 2019-12-17 06:37:35
问题 I am working on Asp.net MVC 2 app with c# by using vs 2010.I am having below mentioned error when I run my app locally under debug mode. Error message image is as below : Error message text is as below : Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive. Please also make sure that System.Web.SessionStateModule or a custom session state module is included in the <configuration>\<system.web>\<httpModules> section in

Can't run ASP.NET MVC 2 web app on IIS 7.5

泪湿孤枕 提交于 2019-12-17 06:28:09
问题 I'm trying to run an ASP.NET MVC 2 web application under IIS on Windows 7, but I get a 403.14 error. Here are the steps to reproduce: Open Visual Studio 2010 Create a new ASP.NET MVC 2 project called MvcApplication1 Shift+F5 to run the app. You should see http://localhost:{random_port}/ and the page will render correctly. Click on MvcApplication1, and select "Properties". Go to the "Web" section. Select "Use Local IIS Web server" and create a virtual directory. Save. Shift+F5 to run the app.

Validating for large files upon Upload

时间秒杀一切 提交于 2019-12-17 06:27:11
问题 I am working with c# MVC 2 and ASP.NET. One of my forms includes a file input field which allows a use to select any file type which will then be converted into a blob and saved into the database. My problem is that whenever a user selects a file that exceeds a certain amoutn of Mb (about 8) I get a page error that says the following: The connection was reset The connection to the server was reset while the page was loading. I don't mind that there's an 8Mb limit to the files the users are

ASP.NET MVC - Catch All Route And Default Route

▼魔方 西西 提交于 2019-12-17 04:47:15
问题 In trying to get my application to produce 404 errors correctly, I have implemented a catch all route at the end of my route table, as shown below: routes.MapRoute( "NotFound", _ "{*url}", _ New With {.controller = "Error", .action = "PageNotFound"} _ ) However, to get this working, I had to remove the default route: {controller}/action/{id} But now that the default has been removed, most of my action links no longer work, and the only way I have found to get them working again is to add

Has anyone implement RadioButtonListFor<T> for ASP.NET MVC?

旧城冷巷雨未停 提交于 2019-12-17 00:31:38
问题 There was an Html.RadioButtonList extension method in ASP.NET MVC Futures. Has anyone found a code for a strongly typed version RadioButtonListFor<T> . It would look like this in a view: <%= Html.RadioButtonListFor(model=>model.Item,Model.ItemList) %> 回答1: Here is the usage in the aspx page <%= Html.RadioButtonListFor(m => m.GenderRadioButtonList)%> Here is the view model public class HomePageViewModel { public enum GenderType { Male, Female } public RadioButtonListViewModel<GenderType>

Using Windows Authentication with ASP.NET MVC

泪湿孤枕 提交于 2019-12-14 04:16:20
问题 I am sure this is a basic answer, but my search powers are not helping me today. I have an ASP.NET MVC 2 (.NET 3.5) application. It is hosted on IIS 6. For the sake of this question I have two urls. http://example.com/ http://example.com/admin I want admin to be available to any user on the domain, and the root to be available to all users. The server is on the domain but the domain is example1.com, so they are not the same. Since this is ASP.NET MVC there is no Admin folder to set rights on.

ASP MVC import CSS

痴心易碎 提交于 2019-12-14 03:58:35
问题 I am new to ASP.NET MVC and I am trying to include a CSS file into my view. The view is strongly typed and has a List Scaffold Template, it is linked to a master page which itself is linked to a css file and works fine for the master slide but when trying to link the view to a seperate css file I cant as I cannot include tags. Anybody know how I can resolve this? 回答1: <link href="@Url.Content("~/Content/YOURSTYLESHEET.css")" rel="stylesheet" type="text/css" /> 回答2: You should add a new

Detect Browser Refresh vs. Form Submit in ASP.Net MVC 2

*爱你&永不变心* 提交于 2019-12-14 03:58:16
问题 I have an ASP.Net questionnaire application that resubmits data to the same page, showing a different question each time. There are BACK and NEXT buttons to navigate between questions. I would like to detect when the form is submitted due to a browser refresh vs. one of the buttons being pressed. I came across a WebForms approach but don't know how to apply those principals in an MVC 2 application since page events aren't available (as far as I know... I'm pretty new to Microsoft's MVC model)

Problem Using Partial View In for each loop

时光怂恿深爱的人放手 提交于 2019-12-14 03:58:13
问题 I'm a little confused here, I am trying use a partial view in a for each loop like so <% foreach (var item in (IEnumerable<MVCLD.Models.Article>)ViewData["LatestWebsites"]){%> <% Html.RenderPartial("articlelisttemaple", item); %> <% } %> And my partial view looks like this <div class="listingholders"> <h4><%=Html.ActionLink(item.ArticleTitle, "details", "article", new { UrlID = item.UrlID, ArticleName = item.ArticleTitle.ToString().niceurl() }, null)%> </h4> <p><%= Html.Encode(item