model-binding

Why aren't file uploads binding to my viewmodel?

吃可爱长大的小学妹 提交于 2020-01-03 06:01:11
问题 I'm trying to bind file uploads to a ViewModel (as demonstrated in this post). But I can't get the files to bind to the Files property on the ViewModel. Please see the code below. What am I doing wrong? (Edit for clarity - I'd like the uploads to bind to the VM, not have them as an Action parameter.) ViewModel public class PrimaryImageUploadViewModel { public PrimaryImageUploadViewModel() { } public HttpPostedFileBase[] Files { get; set; } public string Title { get; set; } } Action [HttpPost]

Why does WebApi fail to bind a System.Version parameter?

好久不见. 提交于 2020-01-02 09:58:33
问题 UPDATE : solved! Nothing to see here, please move on :-) I have an ApiController method that takes a System.Version parameter. The parameter is passed in the request body, as JSON. This is what gets sent: { "Major": 0, "Minor": 7, "Build": 0, "Revision": 0, "MajorRevision": 0, "MinorRevision": 0 } The routing works - my method is being called - but the parameter has an empty Version object (all values zero). Why? Here's the declaration of the controller method: // POST api/service/details

ASP.NET MVC 4, how to access/modify the view model object (and change view and action method) before it is used as action method parameter?

霸气de小男生 提交于 2020-01-02 05:31:26
问题 Is there any useful hook in ASP.NET MVC (MVC4) which can let you access the Action method parameter (View model) before the action method becomes invoked, and then also (e.g. depending on the value of something you checked in the action method parameter) let you prevent the action method from being invoked, i.e. instead either forward the view model object (action method parameter) to another action method or directly to some view (i.e. without any further processing in an action method) ? If

ASP.NET MVC 3 Custom Action Filter - How to add incoming model to TempData?

青春壹個敷衍的年華 提交于 2020-01-01 16:10:29
问题 I'm trying to build a custom action filter which grabs the incoming model out of the filter context, adds it to tempdata, then does "other stuff". My action method looks like this: [HttpPost] [MyCustomAttribute] public ActionResult Create(MyViewModel model) { // snip for brevity... } Now, i want to add the model to TempData , after the model-binding has kicked in and transformed the form value collection into MyViewModel . How do i do that? public override void OnActionExecuting

How to check for a property attribute inside a custom model binder

自古美人都是妖i 提交于 2020-01-01 09:23:11
问题 I want to enforce that all dates in my system are valid and not in the future, so I enforce them inside the custom model binder: class DateTimeModelBinder : IModelBinder { public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { var value = bindingContext.ValueProvider.GetValue(bindingContext.ModelName); try { var date = value.ConvertTo(typeof(DateTime), CultureInfo.CurrentCulture); // Here I want to ask first if the property has the

ngModel with a bind function not working in ng2

泄露秘密 提交于 2020-01-01 08:28:34
问题 If I do in a template of a component something like: <input [(ngModel)]="myProperty"></input> then it works, but if I do it with a function in my component it does not: <input [(ngModel)]="getMyProperty()"></input> Here is the plunkr. Tested on RC6. Why? 回答1: Try this construction <input [ngModel]="getMyProperty()"></input> use only square brackets. 来源: https://stackoverflow.com/questions/39468450/ngmodel-with-a-bind-function-not-working-in-ng2

ASP.Net Web API model binding not working like it does in MVC 3

£可爱£侵袭症+ 提交于 2020-01-01 07:30:22
问题 I was under the impression that model binding in the ASP.Net Web API was supposed to support binding with the same minimum level of functionality supported by MVC. Take the following controller: public class WordsController : ApiController { private string[] _words = new [] { "apple", "ball", "cat", "dog" }; public IEnumerable<string> Get(SearchModel searchSearchModel) { return _words .Where(w => w.Contains(searchSearchModel.Search)) .Take(searchSearchModel.Max); } } public class SearchModel

Model is null while submitting the form in partial view in MVC5

ぐ巨炮叔叔 提交于 2019-12-31 04:08:08
问题 I am just trying to learn MVC and facing some issues.When I am submitting my partial view, I am getting null in Model Blog inside Create Method. What I am doing wrong and what is the right approach? View(Index.cshtml) @model IEnumerable<Samples.Controllers.Blog> @{ ViewBag.Title = "Index"; } <h2>Index</h2> <p> @Html.ActionLink("Create New", "Create") </p> <table class="table"> <tr> <th>Sample</th> <th>URL</th> <th>Name</th> </tr> @foreach (var item in Model) { <tr> <td> @Html.ActionLink("Edit

Can't get my DropDownListFor to select a selected SelectListItem item in a Dropdown menu

戏子无情 提交于 2019-12-31 02:45:49
问题 I have a collection of items populated to a drop down menu: string myUserName = "PopulatedWithSomeUser"; var users= from x in userRepository.GetAll() select new SelectListItem { Value = x.Id.ToString(), Text = x.Name, Selected = (x.Name == myUserName ) }; This correctly populates an object and sets the selected item. Next I pass this to my View with a ViewModel and try to Populate/select: I tried: @Html.DropDownListFor(model=>model.Users,new SelectList(Model.Users),new {id = "add-user-list",

Model Binding for multipart/form-data (File + JSON) post in ASP.NET Core 1.1

試著忘記壹切 提交于 2019-12-30 18:50:09
问题 I'm attempting to build an ASP.NET Core 1.1 Controller method to handle an HTTP Request that looks like the following: POST https://localhost/api/data/upload HTTP/1.1 Content-Type: multipart/form-data; boundary=--------------------------625450203542273177701444 Host: localhost Content-Length: 474 ----------------------------625450203542273177701444 Content-Disposition: form-data; name="file"; filename="myfile.txt" Content-Type: text/plain << Contents of my file >> ---------------------------