razor

EditorFor/CheckBoxFor boolean adds data-val-required attribute to HTML without required attribute being added to model

﹥>﹥吖頭↗ 提交于 2020-01-22 18:47:09
问题 My model class has a bool property without a Required attribute: public class Test { public bool TestBool1 { get; set; } } Then in my razor view I am using EditorFor (Same thing happens with CheckBoxFor as well): <div> @Html.LabelFor(m => m.TestBool1) @Html.EditorFor(m => m.TestBool1) </div> This results in the following HTML: <div> <label for="TestBool1">TestBool1</label> <input class="check-box" data-val="true" data-val-required="The TestBool1 field is required." id="TestBool1" name=

Razor mvc3 + jquery + UrlAction + PartialViews

百般思念 提交于 2020-01-22 15:25:08
问题 I have a question about jQuery + Razor.. I want to build a javascript variable using razor with @Url.Action and the html attributes will be values of inputs. Like this: var d1 = $('#d1').val(); var d2 = $('#d2').val(); var url = "@Url.Action("Links", "PartialAccount", new { beginDate = "d1", endDate = "d2" })" $("#links").fadeOut("slow").load(url).fadeIn("slow"); How can I do this? Is it the same that below? var url = "/PartialAccount/Links/?beginDate=" + d1 + "&endDate=" + d2; 回答1: You

How do I use Razor values in a javascript function? [duplicate]

梦想与她 提交于 2020-01-22 12:08:09
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: using razor within javascript I would like to place a siimple value from the model on a razor page and use it as a constant value in a javascript function. i.e. <script> var myValue = @Model.myRecord.Count();</script> so that myValue = the record count in my model. I am using myRecord.Count as an example, it could be any value from my model. Is this possible? TIA J OK I stumbled across the following solution:

The controller for path … was not found or does not implement IController

笑着哭i 提交于 2020-01-21 09:20:12
问题 I am writing an application using ASP.NET MVC 5 using c#. I have a need to add a global menu on the upper right hand side of the application. I was advised other SO to use action with ChildActionOnly attribute. So here is what I have done. I created a BaseController like this public class BaseController : Controller { [ChildActionOnly] public ActionResult ClientsMenu() { using (SomeContext db = new SomeContext()) { return PartialView(db.Database.SqlQuery<Client>("SELECT * FROM clients")

The controller for path … was not found or does not implement IController

£可爱£侵袭症+ 提交于 2020-01-21 09:18:47
问题 I am writing an application using ASP.NET MVC 5 using c#. I have a need to add a global menu on the upper right hand side of the application. I was advised other SO to use action with ChildActionOnly attribute. So here is what I have done. I created a BaseController like this public class BaseController : Controller { [ChildActionOnly] public ActionResult ClientsMenu() { using (SomeContext db = new SomeContext()) { return PartialView(db.Database.SqlQuery<Client>("SELECT * FROM clients")

ASP.NET MVC3 Razor - create view from a string?

让人想犯罪 __ 提交于 2020-01-21 09:14:10
问题 Is there a convenient way to return a view from a string instead of having to come from a file on disk? I've implemented a custom VirtualPathProvider that handles retrieving views from a database, but I don't always want the view to be stored in the database. Update 2-15-2011 I stumbled across a very nice open source component that simplifies the process of compiling Razor views in code.I've replaced much of the Virtual Path Provider code with this component, and it's working incredibly well.

Migrating my MVC 3 application to MVC 4

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-20 14:23:33
问题 I really do not know what to do, I'm following this article that shows how to migrate my MVC 3 application manually . I followed all the steps but when running my application the following error occurs: Server Error in '/' Application. Could not load file or assembly 'System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT:

Passing Data to a Layout Page

梦想与她 提交于 2020-01-19 12:47:04
问题 I have a layout page that has variables that need to be filled. Example: @ModelType KarateAqua.schoolModel <html> <body> @RenderBody() <div id="footer"> <div class="content"> <div class="bottom_logo"> <a href="/"><span class="inv">@Model.schoolName</span></a> </div> </div> </div> </body> </html> I don't want to populate this in every ActionResult . Is there a way to pass data to a layout page once and do it for all instances? 回答1: OK since you want this to be set once you can make use of a

Passing Data to a Layout Page

血红的双手。 提交于 2020-01-19 12:46:13
问题 I have a layout page that has variables that need to be filled. Example: @ModelType KarateAqua.schoolModel <html> <body> @RenderBody() <div id="footer"> <div class="content"> <div class="bottom_logo"> <a href="/"><span class="inv">@Model.schoolName</span></a> </div> </div> </div> </body> </html> I don't want to populate this in every ActionResult . Is there a way to pass data to a layout page once and do it for all instances? 回答1: OK since you want this to be set once you can make use of a