razor

Why is a full path to layout required in viewstart file when locations are specified in the view engine?

橙三吉。 提交于 2020-01-14 09:51:48
问题 I am playing with the razor view engine and there's something I don't quite get. The _ViewStart file specifies a layout with the full file path like this: @{ Layout = "~/Views/Shared/_MasterLayout.cshtml"; } As I understand it, the full path and extension must be included. You can't just do this: @{ Layout = "_MasterLayout"; } However the view engine specifies locations to search for the master views: MasterLocationFormats = new string[] { "~/Views/{1}/{0}.cshtml", "~/Views/Shared/{0}.cshtml"

How to capitalize first letter razor

徘徊边缘 提交于 2020-01-14 07:39:06
问题 I am new to MVC and have not found a solution for this online. I have the html as : @Html.DisplayFor(model => model.Address1) <br /> I want all the first letter of address1 to be capital letters e.g. Something Road instead of something road. Now I have a class client and property Address1 and using EF to get the address as follow: public class MyDBContext : DbContext { public DbSet<Client> Clients { get; set; } } Hope it makes sense. 回答1: It's best to keep the presentation layer and the data

How to set numeric editorfor min, max and default values in Razor

我怕爱的太早我们不能终老 提交于 2020-01-14 07:21:23
问题 I have an int value that I want to render as a numeric up down with an id that is"Quantity" , so I do the following in razor: <div class="field-label">@Html.LabelFor(m => model.Quantity)</div> <div class="field-editor">@Html.EditorFor(m => model.Quantity, null, "Quantity")</div> In chrome this gives me the right UI, however I would like to set the min, max and default value so it works like the following code does. <input id="Quantity" type="number" name="quantity" min="0" max="10" value="0"

RazorEngine using anonymous objects RuntimeBinderException

不羁的心 提交于 2020-01-14 06:45:41
问题 I'm using RazorEngine in a templating solution. I have to use anonymous objects for my model data. The code: string template = @" Name: @Model.name @foreach(var person in @Model.People) { <row> <column header=""Name"" width=""5cm"">@person.Name</column> <column header=""Age"" width=""5cm"">@person.Age</column> </row> }"; var personList = new List<object>(); personList.Add(new { Name = "Bob", Age = 25 }); personList.Add(new { Name = "Peter", Age = 30 }); var model = new { name = "Henry",

Client side script variables scope for multiple opened tabs of browser issue

妖精的绣舞 提交于 2020-01-14 04:19:31
问题 I have a jquery script in my shared _Layout.cshtml , which records the last click and logs out the user after a specific time interval. The problem that arises is that when more than 1 pages are opend (i.e, in multiple tabs of browser, different pages of same application are opened), if any page remains idle for specified time, it logs out the user. and the other page that the user is currently working on, when user clicks, it throws exception (which is obvious, because user has been logged

Can't write razor variable inside HTML ID/Class element dynamically

て烟熏妆下的殇ゞ 提交于 2020-01-14 03:22:07
问题 I've been trying to improve my MVC website (it uses the GMAPS API) by creating a button (avoid tolls) to update travel distances. The idea is the following Before pressing the button: Lisbon-Madrid: 500km in 4h30 Madrid-Paris: 1000 km in 9h15 After pressing the button: Lisbon-Madrid: 550km in 6:50 Madrid-Paris: 1100km in 13:55 In order to do so I wrote the following code: Before clicking the button: <div id="collapse2" style="display:none"> @{ TripData ThisTripData = new TripData();//A

Html.BeginForm inside of Html.BeginForm MVC3

狂风中的少年 提交于 2020-01-14 02:32:32
问题 I have a main view that renders two partial views. The main view encompasses both of the partial views within a form. Each of the partial views also contain forms. All 3 views share the same viewmodel. What I want to do is encapsulate the data from all views with the main view, and run specific Controller action results with the partial views. I want to know if this is even possible. When debugging I see that my content always posts to the HTTPPost of the Main views form. I have submit

ASP.NET Core Model null error in the Index view

吃可爱长大的小学妹 提交于 2020-01-13 19:34:21
问题 Please see the Error section below. Other related code is as follows: Model : public class Blog { public int BlogId { get; set; } public string Url { get; set; } public List<Post> Posts { get; set; } } public class Post { public int PostId { get; set; } public string Title { get; set; } public string Content { get; set; } public int BlogId { get; set; } public Blog Blog { get; set; } } BlogPostController public IActionResult Index() { return View("~/Views/BlogsTest/Index.cshtml"); } View

Polymorphism in Entity Framework

倖福魔咒の 提交于 2020-01-13 18:11:08
问题 The concrete classes ( BankAccount and CreditCard ) are not visible on controller. I'm stuck with this issue. I'm using the example from this site: http://weblogs.asp.net/manavi/archive/2010/12/28/inheritance-mapping-strategies-with-entity-framework-code-first-ctp5-part-2-table-per-type-tpt.aspx The view The CreateUser : If the CreditCard was selected it should be associated to the User class. The diagram The code UserController : [HttpPost] public ActionResult Create(User user)//The Watch

Polymorphism in Entity Framework

微笑、不失礼 提交于 2020-01-13 18:09:12
问题 The concrete classes ( BankAccount and CreditCard ) are not visible on controller. I'm stuck with this issue. I'm using the example from this site: http://weblogs.asp.net/manavi/archive/2010/12/28/inheritance-mapping-strategies-with-entity-framework-code-first-ctp5-part-2-table-per-type-tpt.aspx The view The CreateUser : If the CreditCard was selected it should be associated to the User class. The diagram The code UserController : [HttpPost] public ActionResult Create(User user)//The Watch