asp.net-mvc-5

Injecting a nullable dependency via constructor requires unity to register that nullable dependency

我的未来我决定 提交于 2019-12-12 02:17:09
问题 Just wondering if anyone had this scenario with Unity(as an IoC container) where the class has two injected dependencies(interfaces) where one dependency can be null. For example: public MyServiceDll(IRepository repository, ICanBeNullDependency canBeNullDependency = null) { _repository = repository; _canBeNullDependency = canBeNullDependency; } ICanBeNullDependency is from another assembly. MyServiceDll is another assembly. MyServiceDll is referenced by web api and injected its interface in

JqGrid Inline Adding Record Save

家住魔仙堡 提交于 2019-12-12 02:17:05
问题 I've gone through many of the questions regarding adding records inline in JqGrid but I haven't been able to figure it out. I have inline editing working and adding a record using a modal popup. I'm using ASP.NET MVC5 with EF. I have the add button already working with a modal popup and the record saves to the database, but what I need is for an empty line to be added to the end of the grid (which I have working) and for the record to save to the database when the enter key is pressed after

Entity Framework seeding causes insert statement conflict with foreign key

被刻印的时光 ゝ 提交于 2019-12-12 02:07:35
问题 I have a simple model: class Employee { int EmployeeId {get;set;} List<Task> Tasks {get;set;} } class Manager { int ManagerId {get;set;} List<Task> Tasks {get;set;} } class Task { int TaskId {get;set;} EmployeeId {get;set;} ManagerId {get;set;} [ForeignKey("EmployeeId")] Employee Employee {get;set;} [ForeignKey("ManagerId")] Manager Manager {get;set;} } class Task1 : Task { } class Task2 : Task { } when I try to seed the database I get an exception, this is how I'm seeding: Employee employee

Performance of a static class that stores all strings in one place

倖福魔咒の 提交于 2019-12-12 01:56:34
问题 I am considering to refactor my code by creating a static class that holds all strings in one place for messages/keys/etc used all over in the website. It would ease maintenance. Now, my concern is the following. From my experience in php, the speed of load was very important. I had to balance what to hardcode and what to dynamically generate. In general, how would the loading speed be impacted by my refactoring? Since C# web application is precompiled, would this not really be an issue to

JQuery UI AutoComplete ASP.NET MVC5 rendering as a list

大城市里の小女人 提交于 2019-12-12 01:53:20
问题 In an ASP.NET MVC5 application, I have an AutoComplete box using JQuery UI. The problem is that the suggestions for the AutoComplete appears to be using <li> elements. Like you can see, when i type "r" in "NomProprio" field, I see a list with 2 "Robin". (It's normal, in my database, I have 2 users with "Robin" as name). But the names appears like a list. I don't want that. I want something like that : http://jqueryui.com/autocomplete/. Here is my View Create.cshtml with scripts : @Html

Implementing IEqualityComparer in C# .NET MVC

醉酒当歌 提交于 2019-12-12 01:48:45
问题 I've implemented a custom comparer like following: public class CustomComparer : IEqualityComparer<StoredEmails> { public static readonly IEqualityComparer<StoredEmails> Instance = new CustomComparer(); public bool Equals(StoredEmails x, StoredEmails y) { return x.Email == y.Email; } public int GetHashCode(StoredEmails x) { return x.Email.GetHashCode(); } } This one basically compares two lists (two equally same typed lists) and adds ONLY MISSING emails from that list to the new one and then

Model Validation not working with all properties

醉酒当歌 提交于 2019-12-12 01:47:24
问题 I have the following ViewModel: public class MyViewModel:IValidatableObject { public int Id { get; set; } public string Name { get; set; } public DateTime? Birthday { get; set; } public int Status { get; set; } public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) { if (string.IsNullOrWhiteSpace(Name)) yield return new ValidationResult("Please fill the name", new string[] { "Name" }); if (Birthday.HasValue == false) yield return new ValidationResult("Please fill

Post an HTML Table to ADO.NET DataTable

依然范特西╮ 提交于 2019-12-12 01:45:40
问题 I have a HTML table as below in my View: <table id="tblCurrentYear"> <tr> <td>Leave Type</td> <td>Leave Taken</td> <td>Leave Balance</td> <td>Leave Total</td> </tr> @foreach (var item in Model.LeaveDetailsList) { <tr> <td>@Html.TextBoxFor(m => item.LeaveType, new { width = "100" })</td> <td>@Html.TextBoxFor(m => item.LeaveTaken, new { width = "100" })</td> <td>@Html.TextBoxFor(m => item.LeaveBalance, new { width = "100" })</td> <td>@Html.TextBoxFor(m => item.LeaveTotal, new { width = "100" })

Get Layout name in Controller method

我是研究僧i 提交于 2019-12-12 01:44:46
问题 I'm using MVC 5 and want to override the below View method in my MVC controller protected internal virtual ViewResult View(string viewName, string masterName, object model) I can have a number of different layout views so want to get the current layout name at runtime and pass it to the overriden view method. How do I get the layout name at runtime in the controller? EDIT I don't think I need to create a custom view engine for what I need to do. I basically only want to set a ViewBag value

i18n with RenderAction

人走茶凉 提交于 2019-12-12 01:41:53
问题 I have some fragments in a view as follows: @Html.RenderAction("Foo","Home") Then all the controllers extends BaseController class HomeController : BaseController{ protected override IAsyncResult BeginExecuteCore(AsyncCallback callback, object state) { .... // http://afana.me/post/aspnet-mvc-internationalization.aspx } } What happens is, for every RenderAction call, this is executed as well. But it doesnt need to cause they are child actions. If i have 3 RenderAction call, the above code is