razor-2

MVC4 Razor difference in @model and @inherit in view header?

蹲街弑〆低调 提交于 2019-11-30 11:05:54
To make a view strongly typed we can use @model and @inherit . Can you please tell me what the difference is between both of them? Edit: Please see this example . The difference is as follows: if your view inherits from WebViewPage<T> then your model directive points to T . In other words, these two are equivalent @inherits System.Web.Mvc.WebViewPage<ModelClass> and @model ModelClass Reference: http://weblogs.asp.net/scottgu/archive/2010/10/19/asp-net-mvc-3-new-model-directive-support-in-razor.aspx They are the same (i.e. indicate strongly-typed model classes) but @inherit is more verbose

Visual Studio 2015 Razor View MVC Types not recognized

无人久伴 提交于 2019-11-30 07:54:31
I installed Visual Studio 2015 and rebooted. The "MVC" types are not recognized in 2015 but are still recognized in 2013. This is my "Views" web.config: <configuration> <configSections> <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />

ASP.NET MVC 4 override emitted html name and id

独自空忆成欢 提交于 2019-11-30 07:48:29
I'm trying to change the emitted name of the html input created by @Html.HiddenFor . The code I'm using this: @Html.HiddenFor(e => e.SomeProperty, new { @id = "some_property", @name = "some_property" } Now this works for the id , however it doesn't work for the name. Now I don't really care for the id now, I need the name to change, because that's the one that get's posted back to the target server. Is there A property I can apply on SomeProperty in my model? A way in the Html.HiddenFor to override the name property? Or am I stuck to do a plain <input ...> by hand? You need to use the Html

MVC and Entity Framework Html.DisplayNameFor with Composite ViewModel

末鹿安然 提交于 2019-11-29 16:47:34
问题 I’m fairly comfortable with MVVM using WPF/Silverlight but this is my first attempt at an MVC Web Application…just an fyi for my background. I’ve created a controller called TestSitesController which was auto generated from from the “Site” model class in my Entity Framework Model (the template that generates the read/write actions and views). The only thing I modified was in 3 spots there was a default parameter of Guid id = null for some methods. I just got rid of the “ = null” all works

MVC4 Razor difference in @model and @inherit in view header?

你离开我真会死。 提交于 2019-11-29 16:37:35
问题 To make a view strongly typed we can use @model and @inherit . Can you please tell me what the difference is between both of them? Edit: Please see this example. 回答1: The difference is as follows: if your view inherits from WebViewPage<T> then your model directive points to T . In other words, these two are equivalent @inherits System.Web.Mvc.WebViewPage<ModelClass> and @model ModelClass Reference: http://weblogs.asp.net/scottgu/archive/2010/10/19/asp-net-mvc-3-new-model-directive-support-in

Is there a benefit to using @Url.Content(“~”)

流过昼夜 提交于 2019-11-29 11:24:39
I'm new to MVC4/razor2, and I think understand the general benefit of using @Url.Content and @Url.Action - if my routing or virtual directory changes, magic-url-strings are correctly rendered. I'm looking at some legacy Javascript-with-razor code in a view that is peppered with '@Url.Content("~")' . This renders out as '/' - or, website root. Which.... would always be the case, no? Or is there some situation in which this could be rendered differently? Note: it is not ~/ - just plain ol' tilde. I'm planning on extracting the razor calls to helper-functions, and moving main block of JavaScript

ASP.NET MVC 4 override emitted html name and id

只愿长相守 提交于 2019-11-29 10:31:29
问题 I'm trying to change the emitted name of the html input created by @Html.HiddenFor . The code I'm using this: @Html.HiddenFor(e => e.SomeProperty, new { @id = "some_property", @name = "some_property" } Now this works for the id , however it doesn't work for the name. Now I don't really care for the id now, I need the name to change, because that's the one that get's posted back to the target server. Is there A property I can apply on SomeProperty in my model? A way in the Html.HiddenFor to

C# syntax to initialize custom class/objects through constructor params in array?

梦想与她 提交于 2019-11-29 09:13:01
I have a class with minimum 4 variables and I have made a constructor for the class so that I can initialize it with MyClass testobj = new MyClass(1234,56789,"test text", "something else", "foo"); Works fine. Then I have an array of these, that I need to parse in a loop, so I would like to get some static data into this array. My approach was: MyClass[] testobjlist = new MyClass { new MyClass(1001,1234,"Text 1", "abcdefghijklm", "ding"), new MyClass(1002,2345,"Text xx", "bla bla", "dong"), new MyClass(1003,8653,"Text yy", "blah blah even more", "bamm!") } but somehow this gives me a weird

What is the syntax for a strongly-typed ActionLink in MVC 4 with MVC 4 Futures?

谁都会走 提交于 2019-11-29 03:42:08
I am using a new MVC 4 Internet application template with Visual Studio 2012. I have installed the Nuget package for MVC 4 Futures. In my _Layout.cshtml I am building the navigation menu. This works and builds the correct URL: @Html.ActionLink("Customers", "Index", "Customers") This is what I would like to work, a strongly-typed variation: @Html.ActionLink<CustomersController>(c => c.Index(), "Customers", null) It griefs on "Cannot choose method from method group. Did you mean to invoke a method?", but something tells me that's not the real issue. This compiles and outputs the right HTML, but

Possible breaking change in MVC4 Razor that can be fixed with “@:@”

故事扮演 提交于 2019-11-28 00:44:52
I recently upgraded my website from ASP.NET MVC3 (Razor) to MVC4 (Razor2), and in doing so found what seemed like a breaking change in the Razor view engine. The scenario (greatly simplified) is shown below. @model IEnumerable<string> @{ Layout = null; } <!DOCTYPE html> <html> <body> <div> @foreach (var x in Model) { @string.Format("Foo bar: {0}", x) // Errors in MVC4/Razor2 } </div> </body> </html> This works fine in MVC3/Razor, however in MVC4/Razor2 the string.Format line results in an error of: Unexpected "string" keyword after "@" character. Once inside code, you do not need to prefix