model-binding

EF4.3 Code-First, MVC, Lazy Loading After Attaching in POST Action

杀马特。学长 韩版系。学妹 提交于 2019-12-06 09:56:53
问题 I'm using Entity Framework 4.3 with Code-First in an MVC 3 application. I have a POST action that gets an entity as its' parameter, and then marks the entity as modified to update the database. It's a Document entity that has a reference to a File Type. [HttpPost] public ActionResult Example(Document model) { // fileType is null, as expected var fileType = model.FileType; // attach and mark the entity as modified, save changes Context.Entry(model).State = EntityState.Modified; Context

MVC3 Model binding pagedlist to ViewModel with custom EditorTemplate and Partial View

无人久伴 提交于 2019-12-06 08:44:26
问题 Im trying to produce a paged table of results which is contained in a Partial view. It is dynamically refreshed with ajax calls. Im reproducing this on a number of pages where it works perfectly, however on a particular page i require the values of the table rows to be bound and returned with the ViewModel. To achieve this i have tried to use an EditorTemplate for the custom object im using for the PagedList collection. The problem lies where the editortemplate which appears on the

DataTable Model Bind in Mvc

扶醉桌前 提交于 2019-12-06 07:19:00
I'm using asp.net mvc with aspx view engine to read from an excel file, extract contact information from that, display it to the user and when he\she confirms it would save them in database. Now in my page I got my DataTable as Model and with a foreach loop I'm showing that to the user. then I have a submit button that when the user click on it I want my datatable back to the Action in a Controller. but my Datatable is null. How can I have my datatable back to my controller ? aspx first line : <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Authenticated.master" Inherits="System

If I need to retrieve an object from a custom model binder should the binder interact with the service layer, the repository layer, or …?

纵然是瞬间 提交于 2019-12-06 06:07:30
问题 If I have a class similar to this: public class Person { public string firstName { get; set; } public string lastName { get; set; } public Pet myPet { get; set; } } When I create a custom model binder, the Post from my form will not be sending in a Pet, it would send in data like this: firstName: "myFirstName" lastName: "myLastName" myPet: "myPetsName" Since the Pet's name is passed in, and not the actual Pet object, the Pet object needs to be retrieved from within the model binder. My

Hydrating ViewModels in ASP.NET MVC

牧云@^-^@ 提交于 2019-12-06 05:52:35
问题 I have a page that is made up of many user controls. The view model for this page is rather complex. public class ComplexViewModel { public ObjectA ObjectAProperty { get; set; } public List<Things> ListOfThings { get; set; } public List<ThingCategories> ListOfThingCategories { get; set; } public List<ThingTypes> ListOfThingTypes { get; set; } public List<ThingOptions> ListOfThingOptions { get; set; } public int ChosenThingCategoryId { get; set; } public int ChosenThingTypeId { get; set; }

How to bind an Array in MVC Core

主宰稳场 提交于 2019-12-06 05:51:17
问题 I try to bind an object like this in a Action public class MonthDataViewModel { public int Year { get; set; } public int Month { get; set; } public IEnumerable<MoneyDataItemViewModel> MoneyCosts { get; set; } } public class MoneyDataItemViewModel { public string Title { get; set; } public decimal Cost { get; set; } } Is that possible? How do i design the form? I try a few times but the property MoneyCosts won't be bind , and this is the data i submited: Year=2016 Moneh=8 MoneyCosts.Title=ABC

MVC model binding naming convention for child objects?

喜你入骨 提交于 2019-12-06 05:33:12
问题 I'm having trouble with default model binding naming convention when there is a child property. For example: I have a ViewModel which looks something like this: public class UserViewModel { public User BusinessObject { get; set; } } My User class has a property called "NetworkLogin" My View has something like this: <%: Html.LabelFor(model => model.BusinessObject.NetworkLogin)%> <%: Html.TextBoxFor(model => model.BusinessObject.NetworkLogin)%> Auto-Fill And my controller, what I'd like to do,

What, exactly, does a modelbinder do? How to use it effectively?

自闭症网瘾萝莉.ら 提交于 2019-12-06 04:36:32
问题 I was researching something and came across this blog post at buildstarted.com about model binders. It actually works pretty darn well for my purposes but I am not sure exactly whats going on behind the scenes. What I did was create a custom ModelBinder called USerModelBinder : public class UserModelBinder : IModelBinder { public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { ValueProviderResult value = bindingContext.ValueProvider.GetValue("id");

MVC Web API Binding Model to a Derived Class

时间秒杀一切 提交于 2019-12-06 03:56:53
I am looking at how to bind a model to a derived class within MVC Web API, the issue I have is that I think I have found about 5 ways of doing it... What I have is: Models -> ModelBase ModelA : ModelBase ModelB : ModelBase Controller then containers the method: Post(ModelBase model) {} The data that is posted will be ModelA or ModelB, I want to add information to the HTTP Request metadata (think Content-Type: application/json; type=ModelA) and based on this tell MVC to bind the posted content to either A or B. In code I imagine something like: Bind(request, bindingContext) { // check request

ASP.NET MVC Updating a list of objects on one form? (model binding to a list)

久未见 提交于 2019-12-06 03:22:09
Quick question regarding updating a list of items in asp.net mvc. Basically I have an edit action method that returns a collection of objects (incidentally, the table structure of which looks as follows 'testID, assetID, Result' - a link table). I basically want this items to be displayed one after another in a form and to be able to edit them. The form should post back and the modelbinder do its magic. But, its not that easy. I have scoured the net and it seems the majority of the information about this stuff seems to be a little out of date. I've come across this post , which has not been