asp.net-mvc-5

MVC @model meaning

喜你入骨 提交于 2019-12-06 01:49:35
in MVC5 , what does @model , @html and @using mean, why and when we usually use ( @ ) and which word follow it ? For example : @model MVC_Project2.Models.stufftable is written in the first of re.cshtml page stufftable is a table which is belong to users to create new user and the following code is written in the same page to create two textbox with two labels two labels to show the login page : @using (Html.BeginForm()) { <div> @Html.LabelFor(u => u.stuffname) @Html.TextBoxFor(u => u.stuffname) </div> <div> @Html.LabelFor(u => u.stuffpass) @Html.PasswordFor(u => u.stuffpass) </div> <input type

How to Insert to Master-detail tables in ASP.NET MVC 5

可紊 提交于 2019-12-06 01:38:17
I have Orders table and OrderDetails table in DB. With Entity Framework 6 I have obtained a model so I have classes generated from it. I also generated controllers and views from the Orders table. Orders folio (PK) date customer (FK) OrdersDetail folio (FK) -- to the Orders table product (FK) price quantity The generated Create Post action is the following: [HttpPost] [ValidateAntiForgeryToken] public ActionResult Create([Bind(Include = "folio,date,customer")] Orders order) { if (ModelState.IsValid) { db.Orders.Add(order); db.SaveChanges(); return RedirectToAction("Index"); } ViewBag.cliente =

28 seconds difference in DateTime column after exporting from Kendo Grid to Excel

孤街浪徒 提交于 2019-12-06 00:39:40
We have a few grids in our web application and we use Kendo for ASP.Net MVC. Some clients are reporting that dates are different when they export the grid data to Excel. As an example, the first row comes from the controller as { "SaleDate": "2018-05-30T00:00:00", "SaleDateAndTime": "2018-05-30T08:01:40.673" } . After exporting to excel, the corresponding cell values are: 05/29/2018 23:59:32 and 05/30/2018 08:01:12 , respectively. I tried exporting dates with different time values and the difference after exporting to excel is always of 28 seconds. This only happens on some clients (timezones

Places you can add password validation in MVC?

自闭症网瘾萝莉.ら 提交于 2019-12-05 22:35:59
I've got a "ForceChangePassword" page for after "ForgotPassword" and it is randomly throwing two length requirements on the "NewPassword" field. The problem is, I never added a length requirement of 7 and have no idea where it is coming from or how to change it. Errors from ModelState The New password must be at least 6 characters long. The 'New password' field is an invalid password. Password must have 7 or more characters. if (!ModelState.IsValid) { return View(model); } // Only line executed in the POST Action. I set the length requirement to 6 on the ViewModel via Attribute (see below). I

Asp.net MVC5 with Bootstrap EditorFor size

独自空忆成欢 提交于 2019-12-05 21:07:58
问题 I have some modifications to bring to a form which use EditorFor (and using MVC5) and I can't find the way of setting the size of the text box ... I tried the hard way with: @Html.EditorFor(model => model.Nom, new{@style="width:400px"}) But this did not work.. Is there an easy way? 回答1: In MVC up to version 5, EditorFor does not allow you to specify html elements in that way. It can only be used in non-editor contexts, like TextBoxFor, etc... In MVC 5.1 they added the ability to specify html

Entity Framework Seed not working

隐身守侯 提交于 2019-12-05 20:29:29
I have this on my web.config. <add name="AppDataContext" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\AppDatabase.mdf;Initial Catalog=AppDatabase;Integrated Security=True" providerName="System.Data.SqlClient" /> Global.asax APplication Start Database.SetInitializer<AppDataContext>(new AppDataContextInitializer()); AppDataContextInitializer.cs public class AppDataContextInitializer : System.Data.Entity.CreateDatabaseIfNotExists<AppDataContext> { protected override void Seed(AppDataContext context) { #region Seed Modules context.ModuleList.Add(new Module() { Id

Override view in ASP.NET MVC site not working

↘锁芯ラ 提交于 2019-12-05 20:10:28
I have a separate project in my solution that contains some Controllers and compiled views. I use those controllers for base classes to other controllers in my MVC application and the views are compiled using RazorGenerator. Lets say B is Base Controller with non abstract action method SomeAction that returns View("_MyView"). _MyView.cshtml is compiled using RazorGenerator. Lets say controller A inherits B but doesn't override SomeAction . I've tried to make another view "~/Views/A/_MyView.cshtml" to override the default one, but it doesn't work. My question is how can I accomplish this?

POST to MVC controller IEnumerable nested Model is null when I don't select checkboxes in order

家住魔仙堡 提交于 2019-12-05 20:08:55
When I'm trying to get values in Post the values of checkboxes are set to NULL when I don't check then in order (1, 2, 3, etc). I need to select any of them in no order (i.e. 4, 5). MODEL: public class AssignUsersViewModel { [Display(Name = "Check to select")] public bool Select { get; set; } public int Id { get; set; } [Display(Name = "App. Username")] public string UserName { get; set; } [Required] public string GivenName { get; set; } [Required] public string Surname { get; set; } [Display(Name = "Roles")] public IList<Roles> Roles { get; set; } } public class AssignUsersAddModel { public

MVC5 placeholder for input not working

醉酒当歌 提交于 2019-12-05 19:34:04
My code is like this @Html.EditorFor(model => model.CreatedUser, new { htmlAttributes = new { @class = "form-control" ,@placeholder = "Your Placeholder Text" }}) I expect the placeholder to come up as I added in the code, but it's not showing. Can anyone point out what I am doing wrong? Output HTML <input class="text-box single-line" id="CreatedUser" name="CreatedUser" type="text" value="" autocomplete="off" style="cursor: auto; background-attachment: scroll; background-position: 100% 50%; background-repeat: no-repeat;"> That EditorFor overload that accepts the htmlAttributes is MVC 5.1 only.

MVCSiteMapProvider breadcrumbs incorrect parent node id

风格不统一 提交于 2019-12-05 19:22:47
I have this sitemap: <mvcSiteMapNode title="Projects" controller="Projects" action="Index" key="Home" visibility="!*"> <mvcSiteMapNode title="Projects" controller="Projects" action="Index"> <mvcSiteMapNode title="Project" controller="Projects" action="Details" preservedRouteParameters="id"> <mvcSiteMapNode title="Session" controller="Sessions" action="Details" preservedRouteParameters="id"> <mvcSiteMapNode title="Edit Session" controller="Sessions" action="Edit" preservedRouteParameters="id"/> </mvcSiteMapNode> </mvcSiteMapNode> </mvcSiteMapNode> <mvcSiteMapNode title="My Account" controller=