asp.net-mvc-2

Getting index value on razor foreach

a 夏天 提交于 2019-11-27 01:32:49
问题 I'm iterating a List<T> in a razor foreach loop in my view which renders a partial. In the partial I'm rendering a single record for which I want to have 4 in a row in my view. I have a css class for the two end columns so need to determine in the partial whether the call is the 1st or the 4th record. What is the best way of identifying this in my partial to output the correct code? This is my main page which contains the loop: @foreach (var myItem in Model.Members){ //if i = 1 <div class=

Implementing a Custom Identity and IPrincipal in MVC

六月ゝ 毕业季﹏ 提交于 2019-11-27 01:20:30
问题 I have a basic MVC 2 beta app where I am trying to implement a custom Identity and Principal classes. I have created my classes that implement the IIdentity and IPrincipal interfaces, instantiated them and then assigned the CustomPrincipal object to my Context.User in Application_AuthenticateRequest of the Global.asax. This all succeeds and the objects look good. When I begin to render the Views the pages are now failing. The first failure is in the default LogoOnUserControl view on the

MVC controller is being called twice

心已入冬 提交于 2019-11-27 01:17:50
I have a controller that is being called twice from an ActionLink call. My home page has a link, that when clicked calls the Index method on the Play controller. An id of 100 is passed into the method. I think this is what is causing the issue. More on this below. Here are some code snippets: Home page: <%= Html.ActionLink("Click Me", "Index", "Play", new { id = 100 }, null) %> Play Controller: public ActionResult Index(int? id) { var settings = new Dictionary<string, string>(); settings.Add("Id", id.ToString()); ViewData["InitParams"] = settings.ToInitParams(); return View(); } Play view: <%@

Iframe, cross-domain cookies, p3p policy, and safari with error: A required anti-forgery token was not supplied or was invalid

一曲冷凌霜 提交于 2019-11-27 01:11:04
问题 I asked this question a while back and found that IE blocks cross-domain cookies in an iframe unless you set a p3p policy. So far, the p3p fix has worked beautifully in ie. However, now we are getting the same error in safari. I found an article with a different p3p policy for safari. I added this code to set up the p3p policy, but I am still getting a request verification token error. public static void SetP3PCompactPolicy() { HttpContext current = HttpContext.Current; if (current.Request

MSBuild DeployOnBuild=true not publishing

拟墨画扇 提交于 2019-11-27 00:51:42
问题 I have a Visual Studio 2010 MVC2 web application that I'm building via the command line using Hudson. I'd like to make Hudson publish a web output, so I added the DeployOnBuild=true and CreatePackageOnPublish=True tags to my command line. My command is: C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe /target:Clean,Build /property:Configuration=Debug;DeployOnBuild=True;CreatePackageOnPublish=True; [my project name.csproj] Running this command on my development machine (Windows 7)

How can we set authorization for a whole area in ASP.NET MVC?

≯℡__Kan透↙ 提交于 2019-11-27 00:40:48
问题 I've an Admin area and I want only Admins to enter the area. I considered adding the Authorized attribute to every controller in the Admin area. Isn't there an elegant solution or is this feature not there in the framework itself? EDIT: I'm sorry, I should to have mentioned this before. I'm using a custom AuthorizedAttribute derived from AuthorizeAttribute. 回答1: Web.config-based security should almost never be used in an MVC application. The reason for this is that multiple URLs can

How to get the HTML id generated by asp.net MVC EditorFor

痞子三分冷 提交于 2019-11-27 00:32:56
问题 I use the HTML Helpers to render my fields: <%=Html.EditorFor(m => m.User.Surname)%> and the output would be something like this: <input class="text-box single-line" id="User_Surname" name="User.Surname" type="text" value="" /> The helper uses the className + '.' è fieldName to build the id. I need to pass the id to a jQuery function. Is there a way to have it without hardcoding it? Maybe an helper which can use the ASP.NET MVC2 conventions? 回答1: ASP.NET MVC 4 has Html.IdFor() built in that

Url.Action parameters?

梦想与她 提交于 2019-11-27 00:29:22
In listing controller I have, public ActionResult GetByList(string name, string contact) { var NameCollection = Service.GetByName(name); var ContactCollection = Service.GetByContact(contact); return View(new ListViewModel(NameCollection ,ContactCollection)); } In ASPX page I call, <a href="<%:Url.Action("GetByList","Listing" , new {name= "John"} , new {contact="calgary, vancouver"})%>"><span>People</span></a> I have a problem in the ASPX code... I can pull the records for the name john. but when I give the contact="calgary, vancouver", the webpage goes to error. How can I call two parameters

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

北城余情 提交于 2019-11-27 00:16:41
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. You should see http://localhost/MvcApplication1/ and an IIS error HTTP Error 403.14 - Forbidden The Web

“The Id field is required” validation message on Create; Id not set to [Required]

﹥>﹥吖頭↗ 提交于 2019-11-27 00:12:42
问题 This is happening when I try to create the entity using a Create style action in Asp.Net MVC 2. The POCO has the following properties: public int Id {get;set;} [Required] public string Message {get; set} On the creation of the entity, the Id is set automatically, so there is no need for it on the Create action. The ModelState says that "The Id field is required", but I haven't set that to be so. Is there something automatic going on here? EDIT - Reason Revealed The reason for the issue is