model-binding

How to use a DI / IoC container with the model binder in ASP.NET MVC 2+?

南笙酒味 提交于 2019-12-17 09:55:52
问题 Let's say I have an User entity and I would want to set it's CreationTime property in the constructor to DateTime.Now. But being a unit test adopter I don't want to access DateTime.Now directly but use an ITimeProvider : public class User { public User(ITimeProvider timeProvider) { // ... this.CreationTime = timeProvider.Now; } // ..... } public interface ITimeProvider { public DateTime Now { get; } } public class TimeProvider : ITimeProvider { public DateTime Now { get { return DateTime.Now;

ASP.NET MVC Model Binder for Generic Type

核能气质少年 提交于 2019-12-17 09:33:50
问题 Is it possible to create a model binder for a generic type? For example, if I have a type public class MyType<T> Is there any way to create a custom model binder that will work for any type of MyType? Thanks, Nathan 回答1: Create a modelbinder, override BindModel, check the type and do what you need to do public class MyModelBinder : DefaultModelBinder { public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { if (HasGenericTypeBase

ExtJs 5 slowly form binding

心不动则不痛 提交于 2019-12-14 03:59:48
问题 I have problem with form panel and binding modelView in ExtJS 5. When form panel after render, values set slowly. Example in fiddle 回答1: This is because the browser is doing a complete layout reflow when changing a Label field (which your WizardOrderRowDisplayField is extending). The Label is not really meant to display changing values. Therefore, the implementation is a bit simplistic. When changing the value it injects new DOM content into the page. When changing DOM content, the browser

MVC3 Html.Editor targeting dictionary is not binding down to the client

寵の児 提交于 2019-12-14 02:59:17
问题 My view model is along the lines of EditViewModel SomeUserType User Dictionary<string, string> Claims In my view I'm trying to bind this as follows @{ int i = 0; foreach (var key in Model.User.Claims.Keys) { <div class="editor"> <input type="hidden" value="@i" name="User.Claims.Index"> <div class="editor-label"> @Html.Label(string.Format("User.Claims[{0}].Key", i)) </div> <div class="editor-field"> @Html.Editor(string.Format("User.Claims[{0}].Key", i)) </div> <div class="editor-label"> @Html

Why can't we use [(ngModel)] and value in same input tag in angular 6

倖福魔咒の 提交于 2019-12-13 17:50:19
问题 My html tag is: <input matInput placeholder="Vehicle Number" name="vehicleNo" [(ngModel)]="vehicleNo" value="vehicle.vehicleNo" > I need to automatically fill the input field and if i enter new thing it need to access in component.ts file. 回答1: In angular if you are using ngModel to bind data then you don't need to use value attribute, it will automatically bind the data. //in ts file export className extends OnInit{ vehicle: any; ngOnInit(){ this.serviceName.functionName().subscribe( data=>{

Manually binding complex model array to controller action

萝らか妹 提交于 2019-12-13 08:08:33
问题 For some reason I'm trying to manually bind an array of a Complex Model but I'm getting a null reference exception in my controller, the binder doesn't retrieve the parameter. I've found this question which is very similar (the only difference is actually the type of the model) but I don't understand why it doesn't work in my case. Here is what I have. In my controller public ActionResult MyAction(ComplexType[] models) { foreach(ComplexType c in models) // Exception at this point, the

How to send jQuery $.get so the Model Binder can bind a string to a parameter?

风流意气都作罢 提交于 2019-12-13 06:42:24
问题 I'm having difficulty getting the Model Binder to work. I thought it was the jQuery, so I asked this question, but after further investigation, I can see that the jQuery is indeed sending the parameter to the server. That's the reason I'm asking a new question - this is no longer a jQuery issue, as I originally thought. Background: What I'm doing is sending a GET request to my Action Method as follows: $.get($(this).attr("href"), { "searchExpression": "schroders" }, function (result) { // do

asp.net core creating/updating a foreignkey

守給你的承諾、 提交于 2019-12-13 06:38:29
问题 I added to my "Todo" class a foreignKey to my "Pharmacy" class. When I add or edit a Todo, no Pharmacy can be linked (from a selectbox). Here's my model: public class Todo { [Key] public int ID { get; set; } public Pharmacy Pharmacy { get; set; } } public class Pharmacy { [Key] public int PharmacyID { get; set; } public string Name { get; set; } public string Pharmacist { get; set; } [DataType(DataType.PhoneNumber)] public int Phone { get; set; } [DataType(DataType.EmailAddress)] public

Same partial view on one page, how to handle binding?

青春壹個敷衍的年華 提交于 2019-12-13 04:44:56
问题 I am still new to MVC. I am currently having a add person page, the page includes person first name, last name and home address which is complex object (include addressline1,addressline2, state etc), delivery address (same to home address). So I'd like to create a partial view which use to display address, but when I submit the form, I can't distinguish which value is for home address, coz home address and delivery address render the same name on the form. MyClass Public class Person { public

MVC Binding nested list

拟墨画扇 提交于 2019-12-13 04:08:54
问题 I have three entities Package, Feature and PackageFeature as follows: Package: PackageId (PK) PackageTitle Feature: FeatureId (PK) FeatureTitle PackageFeature: PackageFeatureId (PK) PackageId (FK) Feature (FK) Quantity I have an MVC view that is typed to "Package" and allows the user to edit the Quantity field on the PackageFeature entity resulting in the source code below, how do I pick this up in the controller? I've tried [Bind(Include = "PackageFeature")]List<Package> package and List