razor

Adding a custom HTML Helper to MVC Project

你离开我真会死。 提交于 2019-12-18 12:40:09
问题 I've been browsing the web trying to find a good example/tutorial detailing how I can create and use my own custom HTML Helpers for my MVC 3 Razor application I found this one which is as follows Adding your own HtmlHelper in ASP.NET MVC 3 I've created a class (trimmed it down a bit) as so using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Linq.Expressions; using System.Web; using System.Web.Mvc; using System.Web.Mvc.Html; namespace

prepopulate Html.TextBoxFor in asp.net mvc 3

对着背影说爱祢 提交于 2019-12-18 12:35:37
问题 I'n new at this, so apologies if this isn't explanatory enough. I want to prepopulate a field in a form in asp.net mvc 3. This works; @Html.TextBox("CompName", null, new { @value = ViewBag.CompName }) But when I want to prepopulate it with a value and send that value to my model, like this; @Html.TextBoxFor(model => model.Comps.CompName, null, new { @value = ViewBag.CompName }) It won't work. Any ideas? Thanks in advance! 回答1: So, I would suggest is to move to using viewmodels rather than the

MVC4 localization. Accessing resx from view

随声附和 提交于 2019-12-18 12:24:45
问题 In my view I would like to access resource strings from the specific local resource on that file.. Just as you know it from web-forms: (string)GetLocalResource("Title"); Painless and smooth. The framework handles which .resx file to get from the culture info code extension (.en-EN.resx). Is that possible in MVC4 with Razore view? And how? Iv'e noticed that i can set the Custom Tool property on the .resx file to PublicResXFileCodeGenerator . That way I can access it from the view. Example: I

How to login with “UserName” instead of “Email” in MVC Identity?

大兔子大兔子 提交于 2019-12-18 12:14:21
问题 I need to set my login to use username instead of email address, how can I change it? 回答1: It's actually using the e-mail address as the username, so in the ASPNetUsers table, you'll see both the username and email fields with the email address. Go into the AccountController, look for Register method (POST). Change this: var user = new ApplicationUser { UserName = model.Email, Email = model.Email}; to this: var user = new ApplicationUser { UserName = model.UserName, Email = model.Email };

HTTP Error 403.14 - Forbidden - MVC4 .net 4.5 bundles

半城伤御伤魂 提交于 2019-12-18 12:13:27
问题 I made a MVC4 application with .net 4.5 using razor engine. It works fine when run locally with visual studio. When I deploy to IIS on windows server 2008 R2(all windows updates done), it appears my bundles do not work and the CCS is not loading. I tried viewing the site on the server, viewed source went to the bundle link for the css, and it loads some css and then there is an IIS error of: HTTP Error 403.14 - Forbidden The Web server is configured to not list the contents of this directory.

Visual Studio 2010 “Publish” does not copy Razor view files

£可爱£侵袭症+ 提交于 2019-12-18 12:12:41
问题 When using the built-in Publish feature of Visual Studio 2010 with a web application that includes Razor views (.cshtml or .vbhtml), the publish service does not copy the Razor view files . This occurs both on a local "File System" publish as well as a remote publish using Web Deploy, using the November 9 Release Candidate. Are there any known workarounds? 回答1: You need to set the build action to "Content" under properties. Edit: You have to do this on each of the files that aren't being

MVC Layout VS MVC Master Page

£可爱£侵袭症+ 提交于 2019-12-18 12:12:37
问题 I'm starting learning MVC4. I came across the two possibilities of creating a View based on a Razor template or a Master Page. I would like to understand the practical differences between the two . For now, I can see that if I create a View using a Master Page, I can override several sections. For example, if my Master defines a "left column" placeholder and a "body" placeholder I can not only define the body for a specific View, but I can also render contents in the "left column" section for

Getting and passing MVC Model data to AngularJS controller

巧了我就是萌 提交于 2019-12-18 12:11:42
问题 I'm pretty new to AngularJS and I'm at a loss here. Right now my MVC program uses Razor to display all the data in my .mdf database (i.e: @Html.DisplayFor(modelItem => item.LastName) ). However, I want to go mostly Angular. I am trying to use ng-repeat to display all of the Model data, but I am not sure how to pass that Model data to the Angular controller and then use it. I have tried serializing the Model to JSON in my ng-init, but I don't think I'm doing it right (obviously). Here is my

MVC DropDownListfor() Basics

三世轮回 提交于 2019-12-18 11:56:44
问题 I have a Model which consist of Employees information. In my model there is a property called City which define the city of Employee in which he lives. The propery is shown below public string City{get;set;} Now I have a view which contains a form which will be filled by a employee to register. I want to use a dropdownlist for selecting cities. I think the below code will be used for dropdown as i discovered. My model name is Employee. @Html.DropDownListFor(m=>m.City,new SelectList()) Please

How to get to Model or Viewbag Variables in a Script Tag

此生再无相见时 提交于 2019-12-18 11:52:19
问题 Vs'12 asp.net C# MVC4 - Int.Appl.Template EF Code First Here is my very simple Script <script class="TractsScript"> $('#Add').click(function (e) { var val = @ViewBag.ForSection; alert(val); }); </script> As per example I am wanting to simply set a variable in my script or USE a Viewbag. or Model. I haven't been able to find an answer in any of the following forums: StckTrace1,StackTraceBetterAnswer Other Things i have tried: var model = @Html.Raw(Json.Encode(Model)) alert(model.Sections);