model-binding

Using one Partial View Multiple times on the same Parent View

為{幸葍}努か 提交于 2019-12-06 01:58:09
问题 I am using MVC3 razor. I have a scenario where I have to use a partial view multiple times on the same parent view. The problem I am having is that when the Parent View gets rendered, it generates same names and ids of the input controls within those partial views. Since my partial views are binded to different models, when the view is posted back on "Save" it crashes. Any idea how can i make the control id/names unique, probably some how prefix them ? Awaiting Nabeel 回答1: Personally I prefer

MVC3 - HiddenFor Dictionary Values

感情迁移 提交于 2019-12-06 01:43:29
I have a dictionary property called Week: public IDictionary<DayOfWeek, Day> Week { get; private set; } And I'm trying to pass its values off to HiddenFor (Days) @Html.HiddenFor(x => x.Week.Values) It has to be a property of the Model so I can't do x.Week.Values.ToList(); How would I go about passing the Dictionary Values to the Html.HiddenFor ? Jason Kulatunga Well since your using HiddenFor , I'm going to assume that you need to rebind the values of the dictionary on form post. To bind a Dictionary to the view, your going to need to do something like this: @foreach (var key in Model.Week

Upload multiple files in MVC3 with model binding

邮差的信 提交于 2019-12-05 23:31:29
So I want to catalogue my record collection. I also want to learn some MVC. So I decided to build a record cataloguing website in MVC. That's how I work. I'm just dipping my toes in but cannot figure out how to upload multiple files to my SQLCE database. I'm open to options here - store the images as BLOBS or simply as filenames and upload the images to the filesystem. My simple model is this: public class Record { [ScaffoldColumn(false)] public int RecordId { get; set; } [Required(ErrorMessage = "Artist is required")] public string Artist { get; set; } [Required(ErrorMessage = "Title is

How to get DataAnnotations working in asp.net 4.5 WebForms?

一个人想着一个人 提交于 2019-12-05 23:06:39
I'm using .net 4.5 WebForms with Model Binding and Entity Framework 5. Part of my webform: <asp:ListView ID="MenteeModuleList" ItemPlaceholderID="itemPlaceHolder" OnCallingDataMethods="MenteeModuleList_CallingDataMethods" ItemType="PFA_Mentorship.BLL.MenteeModuleBL+MenteeModuleGrid" DataKeyNames="MenteeModuleID" SelectMethod="GetMenteeModulesGrid" InsertItemPosition="LastItem" InsertMethod="InsertMenteeModule" runat="server"> <LayoutTemplate> <table runat="server"> <tr runat="server"> <th id="Th1" runat="server">Module</th> <th id="Th2" runat="server">Start Date</th> <th id="Th3" runat="server

ASP.NET MVC Model list binding

江枫思渺然 提交于 2019-12-05 21:50:52
问题 Here is my model: public class Items { public string Foo { get; set; } public string Bar { get; set; } } Controller: public ActionResult Index() { var model = new List<Items> { new Items { Foo = "foo", Bar = "bar" }, new Items { Foo = "ai", Bar = "ia" }, new Items { Foo = "one", Bar = "two" } }; return View(model); } [HttpPost] public ActionResult Index(List<Items> model) { return View(model); } View (Index): @using (Html.BeginForm()) { for (int i = 0; i < Model.Count; i++) { <div onclick="$

ASP.Net MVC Model binding a [Serializable] class

耗尽温柔 提交于 2019-12-05 21:00:49
I have this class [Serializable] public class MyObject { // properties omitted } And this WebAPI controller method: [HttpPost] [ResponseType(typeof(string))] public IHttpActionResult SetMyObject(MyObject o) { // process object } But it fails to model bind to the MyObject class. The object o in the controller method is completely empty, every property is default (so mostly null). Turns out this is because of the [Serializable] annotation on MyObject. Removing that makes model binding work again. Is there a way to keep [Serializable] and fix model binding? Radim Köhler The answer is in the

Inherited interface property not found by Model Binding in MVC3 but works fine in MVC2

半腔热情 提交于 2019-12-05 17:49:10
问题 UPDATE: Problem Solved. Darin Dimitrov's answer contains a link to another, related question. One of the proposed solutions on that page ended up working for us. Original Question The code sample below works in MVC 2 but throws an exception in MVC 3. Does anyone know why MVC 3 introduced this breaking change? Is there a way to get this working in MVC 3 while still allowing me to describe the viewmodel as an Interface from within the view? There is another related question on StackOverflow,

ASP.NET MVC Model Binding with Dashes in Form Element Names

血红的双手。 提交于 2019-12-05 17:21:13
问题 I have been scouring the internet trying to find a way to accomodate dashes from my form elements into the default model binding behavior of ASP.NET's Controllers in MVC 2, 3, or even 4. As a front-end developer, I prefer dashes in my CSS over camelCase or underscores. In my markup, what I want to be able to do to is something like this: <input type="text" name="first-name" class="required" /> <input type="text" name="last-name" class="required" /> In the controller, I would be passing in a C

AngularJS: ng-repeat with key value - updating object

余生长醉 提交于 2019-12-05 16:55:45
问题 I am rendering key:value object array with ng-repeat like this: <div ng-controller="mainCtrl"> <div ng-repeat="record in records"> <div ng-repeat="(key, value) in record"> <input ng-model="key" />: <input ng-model="value" /> </div> </div> </div> JS: var mainCtrl = function($scope){ $scope.records = [ {'key1':'val1'}, {'key2':'val2'} ]; } Problem is that keys and values cannot be updated through input tags. For some reason it becomes one way binding after making ng-repeat iterate over (key

Querystring Model Binding ASP.NET WebApi

纵然是瞬间 提交于 2019-12-05 16:47:29
I have the following model public class Dog { public string NickName { get; set; } public int Color { get; set; } } and I have the following api controller method which is exposed through an API public class DogController : ApiController { // GET /v1/dogs public IEnumerable<string> Get([FromUri] Dog dog) { ...} Now, I would like to issue the GET request as follows: GET http://localhost:90000/v1/dogs?nick_name=Fido&color=1 Question: How do I bind the query string parameter nick_name to property NickName in the dog class? I know I can call the API without the underscore (i.e. nickname) or change