asp.net-mvc-5

Cannot Create()/Edit() record due to Validation?

家住魔仙堡 提交于 2019-12-12 03:07:56
问题 My Inventory Tracking program has a main class called INV_Assets . This includes [ForeignKey] fields for several child tables including INV_Locations : [Required] public int Location_Id { get; set; } [ForeignKey("Location_Id")] public virtual INV_Locations Location { get; set; } Now then, on my Create()/Edit() action methods for INV_Assets I am filling a ViewData[] element with a SelectList to be used on the View (this Select List combines 2 of my INV_Locations fields into one within the

How to ignore validation annotation if field is blank?

孤人 提交于 2019-12-12 02:56:11
问题 I have these classes: Class Parent { [Required] String Name ; Child child ; } Class Child { [Required] Child FirstName ; [Required] Child LastName ; } I have a form showing the Parent entity fields including the Childs's. With my configuration the child's FistName and LastName are required and if left blank causes validation to fail. What I need is have validation pass if both the child's FirstName and LastName are submitted blank. If either FirstName or LastName is submitted then the other

Predicate Builder Issue

白昼怎懂夜的黑 提交于 2019-12-12 02:51:19
问题 Imagine I have 2 database tables.. 1 table holds different sports: |ID| |Sport| 1 Baseball 2 Basketball 3 Soccer The second table holds the ID of the Sports table, so a foreign key Name of Table - TestDB |ID| |SportsID| |Test| 1 1 test1 2 3 test2 3 2 test3 4 1 test4 5 2 test5 Now I am using Predicate Builder to allow the user to search through the table in my web application: [HttpPost] public ActionResult allDailySummaries(int? sport, int? sport1) { List<TestDB> lstTDB = db.TDB.Include(x =>

Complicated relationships vs simple tables Entity Framework CodeFirst

感情迁移 提交于 2019-12-12 02:49:39
问题 Database design question :) Is it smarter to make a lot of interconnected tables (normalize) or is it smarter to duplicate data so queries are simpler? Here is my situation: public class TransferRequest { [Key] public int TransferRequestId { get; set; } public int By { get; set; } public int? For { get; set; } public int PersonId { get; set; } public virtual Person Person { get; set; } [ForeignKey("Transfer")] public int? ExistingTransferId { get; set; } public virtual Transfer

Compilation Error - The compiler failed with error code 1 - asp.net error after publishing

人走茶凉 提交于 2019-12-12 02:44:22
问题 After publishing my asp.net MVC 5 website to the hosting environment, I got the following error message Compilation Error - The compiler failed with error code 1 Nothing else besides the compiler-call itself is shown. 回答1: In my case, the MVC-templates added the following section in the web.config file: <system.codedom> <compilers> <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers

i am trying to have a create form and a list both working with ajax without refreshing page

房东的猫 提交于 2019-12-12 02:43:34
问题 i am working on an application. i am using two partial view in a single view. one of them is a create form for shortcode and the other one lists the shortcodes having a pagination. this is my create form which is partial view @model UniProject.Models.Short_Code <div id="formDiv"> @using (Ajax.BeginForm("Create", "Service", new AjaxOptions { HttpMethod = "post" , UpdateTargetId = "formDiv" })) { <table> <tr> <td>@Html.LabelFor(model => model.ServiceCode)</td> <td>@Html.TextBoxFor(model =>

MVC 5 application on IIS 8 in Windows Server 2012 (virtual machine) is very slow (not only on initial load)

∥☆過路亽.° 提交于 2019-12-12 02:39:22
问题 The goal is to launch an MVC 5 web app on an IIS 8 within a Windows Server 2012 (Standard edition for evaluation from Microsoft) in a virtual machine (VMware Workstation 12 Player, free version) in order to test the whole system for the release. I managed to run the application, but the problem is, that it´s extremely slow. E.g. the index.html is a static HTML page and needs more than 60 seconds to load. But why? In Visual Studio and IIS Express still everything works perfectly. Futher

Setting the context's connection name depending on the user that logs in

流过昼夜 提交于 2019-12-12 02:27:18
问题 This used to be a Web Forms application and I'm rewriting it in MVC. The connection name is stored in the user's details and depending on the user, I need to pass a different connection name. In WebForms this was solved by setting a Session variable in Global.asax and then every time the context is needed, I'd create the context in a using statement, passing the Session variable in the context constructor like this: using (IAccountContext db = new MainContext(Session["cn"]) { } In MVC I'm

Dynamic MVC RadioButton Group Selected Answers

半腔热情 提交于 2019-12-12 02:26:33
问题 I have a dynamically populated list of questions and answers. Two problems: The questions and answers do not display after postback The selected answers are missing Viewmodel public class RegistrationViewModel : RegisterExternalLoginModel { //...etc... public Question Question { get; set; } public Answer Answer { get; set; } public List<Question> Questions { get; set; } public IList<Answer> PossibleAnswers { get; set; } public List<SelectedAnswer> SelectedAnswers { get; set; } public IList

Separating validation logic from business logic in asp.net MVC 5 controller

a 夏天 提交于 2019-12-12 02:19:26
问题 I have an asp.net MVC 5 website. I am using data annotations on the model for validation - eg [Required] public string FirstName { get; set; } However, if I want to do something a bit more complicated with validation, say require a date to be in the future - all examples I have seen just perform validation in the controller - eg: [HttpPost] public ActionResult Edit(MyViewModel vm) { // check date is in future if (vm.mydate < DateTime.Now()) ModelState.IsValid = false; if (ModelState.IsValid)