razor

Why does “Dispose” work, and not “using(var db = new DataContext())”?

旧巷老猫 提交于 2019-12-21 09:09:11
问题 I'm creating a forum which is made up of topics, which are made up of messages. When I try to implement the topic View in my Controller with: public ActionResult Topic(int id) //Topic Id { using (var db = new DataContext()) { var topic = db.Topics.Include("Messages").Include("Messages.CreatedBy").Include("CreatedBy").FirstOrDefault(x => x.Id == id); //include the messages for each topic, and when they were created so that the last message can be displayed on the topic page return topic !=

Why does “Dispose” work, and not “using(var db = new DataContext())”?

喜夏-厌秋 提交于 2019-12-21 09:09:09
问题 I'm creating a forum which is made up of topics, which are made up of messages. When I try to implement the topic View in my Controller with: public ActionResult Topic(int id) //Topic Id { using (var db = new DataContext()) { var topic = db.Topics.Include("Messages").Include("Messages.CreatedBy").Include("CreatedBy").FirstOrDefault(x => x.Id == id); //include the messages for each topic, and when they were created so that the last message can be displayed on the topic page return topic !=

Check is a specific form field is valid

≡放荡痞女 提交于 2019-12-21 09:07:35
问题 I've been searching for a while now and haven't found a solution yet. I'm an ASP.NET and MVC4/Razor2 newbie, so I'm mostly editing the default project. Anyway, my issue is that I'm using Twitter Bootstrap and I need to add an error CSS class on a div if the under-laying field is not valid. So far I have this: <div class="control-group error"> @Html.LabelFor(m => m.Password, new { @class = "control-label" }) <div class="controls"> @Html.PasswordFor(m => m.Password) @Html.ValidationMessageFor(m

ASP.NET MVC3, Enable Razor

不羁岁月 提交于 2019-12-21 08:55:08
问题 I've upgraded an MVC2 project to MVC3 and now want to start using the Razor view engine but when I do Add->View it doesn't give me the option to choose the view engine. I have updated the Web.config in my views folder and have compared with a new MVC 3 project but nothing is working. Any ideas? 回答1: I fixed this by changing the ProjectTypeGuids element in the .csproj file to the following: <ProjectTypeGuids>{E53F8FEA-EAE0-44A6-8774-FFD645390401};{349c5851-65df-11da-9384-00065b846f21};

Where is index.g.cshtml

无人久伴 提交于 2019-12-21 07:54:37
问题 I am trying to work through this tutorial, (ASP.Net Core Razor Pages) but (often) when I build the solution, I get a CS0234 error stating that a namespace is missing from file 'Index.g.cshtml.cd'...….but where does this file exist? I have tried 1. All the build/clean/rebuild solution options. 2. I have restarted Visual Studio 3. I have deleted the DEBUG files and restarted VS and FINALLY 4. I have restarted my PC. The ONLY solution that seems to work, is to delete the entire solution/project

Where is index.g.cshtml

巧了我就是萌 提交于 2019-12-21 07:54:27
问题 I am trying to work through this tutorial, (ASP.Net Core Razor Pages) but (often) when I build the solution, I get a CS0234 error stating that a namespace is missing from file 'Index.g.cshtml.cd'...….but where does this file exist? I have tried 1. All the build/clean/rebuild solution options. 2. I have restarted Visual Studio 3. I have deleted the DEBUG files and restarted VS and FINALLY 4. I have restarted my PC. The ONLY solution that seems to work, is to delete the entire solution/project

Creating an object.cshtml editor template with MVC and Razor

浪尽此生 提交于 2019-12-21 07:34:15
问题 I am looking to create an editor template for Object.cshtml to change the behavior of the Html.EditorForModel() method. I can't find any example of this using Razor. I have seen this example using MVC2 and WebForm view engine but don't know enough about razor to convert it. Even a simple example would be very helpful. 回答1: I'm just going to do the Display template and leave the rest as an exercise for the reader:) @if (Model == null) { <text>@ViewData.ModelMetadata.NullDisplayText</text> }

Razor .cshtml syntax highlighting for vim?

梦想与她 提交于 2019-12-21 07:24:09
问题 I'm looking for a .cshtml vim syntax file. Are there any projects that haven't made it to www.vim.org? 回答1: ":setf html" solves the 80% part :) 回答2: this guy has razor support planned, but is not yet there. However, it does add some features to the existing c# support. https://github.com/OrangeT/vim-csharp 回答3: You can find nice vim-razor plugin in https://github.com/adamclerk/vim-razor $ cd ~/.vim/bundle $ git clone https://github.com/adamclerk/vim-razor 回答4: Settled with adding this to

ASP.NET MVC Razor Won't Accept My Valid Markup

梦想与她 提交于 2019-12-21 07:17:09
问题 I like the Razor syntax a lot, but it certainly falls short of perfect. For example, I have the following block of markup. @if (Model.FeaturedDestinations != null && Model.FeaturedDestinations.Count() > 0) { int column = 0; foreach (var d in Model.FeaturedDestinations) { column++; if (column > 4) { </div> @{ column = 1; } } if (column == 1) { @:<div class="row-fluid"> } <div class="span3"> @RenderDestination(d) </div> } </div> } So, the editor gives me the squiggly lines indicating that I

ASP.NET MVC Razor Won't Accept My Valid Markup

空扰寡人 提交于 2019-12-21 07:16:57
问题 I like the Razor syntax a lot, but it certainly falls short of perfect. For example, I have the following block of markup. @if (Model.FeaturedDestinations != null && Model.FeaturedDestinations.Count() > 0) { int column = 0; foreach (var d in Model.FeaturedDestinations) { column++; if (column > 4) { </div> @{ column = 1; } } if (column == 1) { @:<div class="row-fluid"> } <div class="span3"> @RenderDestination(d) </div> } </div> } So, the editor gives me the squiggly lines indicating that I