w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
MVC Model Binding - Form Post Starts With a Number
You can do this with a custom model binder: public class NotificationModelBinder : DefaultModelBinder { public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { var model = this.CreateModel(controllerContext, bindingContext, bindingContext.ModelType); bindingContext.ModelMetadata.Model = model; var formValue = bindingContext.ValueProvider .GetValue(this.FormField).AttemptedValue; var target = model.GetType().GetProperty(this.FieldToBindTo); target.SetValue(model, formValue); // Let the default model binder take care of the rest return base.BindModel(controllerContext, bindingContext); } private readonly string FieldToBindTo = "_3DSe

Categories : C#

JSON isn't binding to my model
The signature of your controller action method is public string Submit(MonthlyMarketingReport report) So I think in your ajax call it should be data: JSON.stringify({ report: mmr }),

Categories : Asp Net Mvc

ASP.NET MVC Model binding doesn't work with AJAX GET but works with Post
First, just to clear up misconceptions, POST doesn't mean change, necessarily. It's perfectly valid to request via POST when accessing a "function", for lack of a better word. For example: # Request POST /add-xy { "x": 2, "y": 2 } # Response 200 OK 4 Nothing has "changed", but POST is still the most appropriate HTTP verb. That said, there's a fundamental difference between GET and POST requests, namely the concept of a POST "body". A POST body can have a content type and therefore can be interpreted properly on the server-side as JSON, XML, etc. With GET, all you have is a querystring, which is just simply a string. The problem you're having is that with GET, the filter "object" is just a string, and since a string does not implement IFilter the modelbinder can't bind it. However, vi

Categories : Asp Net Mvc

JSON model binding with XML Serialisation attributes in Web API
Post this JSON and see. {"_searchCodes":[ "SYAA113F", "N0TEXI5T", "SYAA112C"] } Remember to set Content-Type: application/json.

Categories : Json

ASP.NET MVC 4 JSON Binding to the View Model - Nested object error
The problem is from your action method parameter: [HttpPost] public ActionResult SaveAddress(AddressViewModel addressViewModel) As you use JSON.stringify(), you send a string to your controller, not an object! So, you need to do some works to achive your goal: 1) Change your action method parametter: [HttpPost] public ActionResult SaveAddress(string addressViewModel) 2) Deserialize that string to an object - that is AddressViewModel: IList<AddressViewModel> modelObj = new JavaScriptSerializer().Deserialize<IList<AddressViewModel>>(addressViewModel); So, your final action method should be like the following: [HttpPost] public ActionResult SaveAddress(string addressViewModel) { IList<AddressViewModel> modelObj = new JavaScriptSerializer().Deserial

Categories : Json

Angularjs models not binding to json template used in http post request
Not sure why you want to use the $rootScope always. Scopes in angular follow prototypical inheritance , so you should be able to access the parent scope attributes from the child scope (This happens for all cases except in directives where an isolated scope can be created). Can you instead using the child scope itself, but reference the elements in the parent scope. You might want to check this SO post for better understanding.

Categories : Javascript

Manually Binding a Model to an ASP.NET FormView using model binding
There's no need to manually assign the Product because data binding takes care of this leg work for you. Firstly, make sure you have some sort of Button in each row of the ListView with a CommandName of Select: <asp:ListView ID="ProductList" runat="server" DataKeyNames="Id" ItemType="Product" SelectMethod="GetProductList"> <ItemTemplate> <%# Item.Name %> <asp:Button ID="SelectButton" runat="server" CommandName="Select" /> </ItemTemplate> </asp:ListView> Secondly, for the SelectMethod of the FormView make sure the product id parameter has the Control attribute specified where the string passed to the constructor must match the id of the ListView Control: public Product GetProduct([Control("ProductList")] int? id) { if (id.HasValue) {

Categories : Asp Net

reasons not to use dataset binding in vb.net
As I said in my comment that's not binding. I think this is one of the many situations where a feature that helps you get started with something small can start to get in the way when you are tackling a bigger and more complex project. Particularly if you are building a system to distribute to multiple clients, who will then have to install and configure the system for themselves, I'd recommend you manage the connections in code; you need that degree of control over what's going on. Conversely if you're writing a little utility to be used in-house you can rely on the connection management provided by VS. Personally anything but the simplest application I manage the connections in code.

Categories : Vb.Net

Binding DataSet to DataGrid in WPF
ok. So here may be the same issue you are dealing with. You can try to set the ItemsSource property as follow: GridData.ItemsSrouce = vDs.Tables["Book"].AsEnumerable();

Categories : C#

Conversion from DataSet to JSON ends up wrapping the JSON string with xml tags
I didn't find any good way to return pure JSON from WCF project nor ASMX despite all "Experts" saying "its easy" Add web page to your project (ASPX) which can use your web service as data source and then to serialize the objects from the web service JSON. By using: JavaScriptSerializer serializer = new JavaScriptSerializer(); String myJSON= serializer.Serialize(<your object>); And "myJSON" will hold the JSON. The JavaScriptSerializer can't handle DataTableDataSet so what you can do is to insert DataSet into DataTable and use the following method to convert it to JSON (string) public static string GetDataTableToJSONString(DataTable table) { List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();

Categories : C#

Binding a dataset/DataTable to a xaml datagrid
You'll need to bind to a property on your view model that returns a DataView. Have a look at http://www.codeproject.com/Articles/30905/WPF-DataGrid-Practical-Examples for more information. E.g: public DataView Items { get { return m_QueryTable.Tables[0].DefaultView; } } Alternatively (and preferably), you could use entities and a repository pattern to abstract the data access logic away from the view models.

Categories : Wpf

How to parse a simple JSON string to a DataSet with Json.Net
Instead of deserializing to a DataSet, have you considered creating a custom class for your data and deserializing to that instead? It might be a little more straightforward to work with. For example, if you define a class like this: class Data { [JsonProperty(PropertyName="w_vendor")] public List<string> Values { get; set; } } Then you can deserialize like this: string json = @"{""w_vendor"":[""914115361"",""914115361"",""914115361"",""914115361"",""914115361"",""914115361"",""914115361"",""914115361"",""914115361"",""914115361"",""914115361"",""914115361"",""914115361"",""914115361"",""914115361"",""914115361"",""914115361"",""914115361"",""914115361"",""914115361"",""914115361"",""914115361"",""914115361"",""914115361"",""914115361"",""914115361"",""914115361"",""914

Categories : Json

Binding a ListBoxFor to a Model in MVC 3 and auto selecting multiple items using another Model
Model public class Admin { private List<int> _selectedEventIds; public List<int> SelectedEventIds { get { return _selectedEventIds ?? new List<int>(); } set { _selectedEventIds = value; } } private List<Events> _eventList; public MultiSelectList EventList { get { return new MultiSelectList( _listeFonctions, "EventId", // dataValueField "EventName" // dataTextField ); } } public Admin() { } public Admin(List<int> selectedEventIds, List<Events> eventList) { SelectedEven

Categories : Asp Net Mvc

Cannot pass view model back to controller using jquery dialog and model binding with Razor MVC 4
I have had issues with MVC accepting collections as parameters similar to this before. I ended up switching my javascript call to doing an $.ajax post ($.post also has some issues sometimes) speficically including a content and data type $.ajax({ type: 'Post', dataType: 'json', url: 'url-goes-here', data: JSON.stringify({ data: data}), contentType: 'application/json; charset=utf-8' }); Not quite as nice as the auto-binding, but it does post the data back even as a collection.

Categories : Jquery

Selecting database model for comma separated dataset
You are thinking of your data in a very relational way, so I would recommend you to normalize your data and use a relational database. Don't worry too much about the performance of JOINs. As long as the joins are on equality of pre-defined secondary keys, and all search-able fields have indexes, the performance should be acceptable. When you really want to look at a No-SQL solution, you could look at graph-based databases like Neo4j (one online demo is surprisingly close to your use-case).

Categories : Mysql

(MVC4 - Razor) List of model in a model don't caught by the post method
The MyId should be correctly received with your existing code. The model binder can only match the value of inputs whose name have a matching property in the form. I.e. if you have an input like this <input name='bikes' ...> then your model should have a property Bikes so that the model binder can transfer the value from the input to the property. In your case you're creating input with dynamic names that doesn't have a matching property name. (NOTE: thei referes to the model you're using as the action parameter). The farthest you can go is giving a series of input elements the same name, i.e. several elements like <input name='categories' ...> and receive it in an array parameter like string[] categories or a model which has a property like string[] Categories {get;set;} In

Categories : C#

Use JSON with jQuery and dataset(how to loop the values)
Perhaps like this (second example) $(function() { var $widget=$("#widget"); $.get($widget.data("load"),function(data) { $.each(data.something,function(key, value) { $widget.append(value); }); });

Categories : Javascript

Newtonsoft JSON- Conversion to/from DataSet causes Decimal to become Double?
I suspect it has something to do with the standard (XML) serialization of DataSet and DataTable. If you write DataSet from the example to a file you'll see that information about the DataTable schema isn't provided. This can be determined when reading the XML file back into a table. The data from your example written to a file gives this result: <NewDataSet> <Table1> <Test>1.23345</Test> </Table1> </NewDataSet> When the DataSet with the DataTable has been read you can't change the type of the column (in my test case when going to/from XML the type is string) but you can .Clone() the DataTable and move/convert the data: var clonedTable = ds.Tables[0].Clone(); clonedTable.Columns[0].DataType = typeof(decimal); foreach (DataRow row in dt.Table

Categories : C#

C# ASP.NET MVC model binding
The difference is in the = sign after the open tag <%. This ensures that the value is written to the output. The first example is simply declaring a value and not doing anything with it. Check out this blog entry for more info on the ASPX view engine tag syntax. This is simplified a lot with Razor syntax, where you are able to just prefix a line in a codeblock with @ in order to write it to output. I don't know if there is a similar functionality in the ASPX view engine though.

Categories : C#

Rails JSON API testing POST request with PARAMS in JSON
I found my answer on a post here(RSpec request test merges hashes in array in POST JSON params), I think what I was doing wrong concerned the arguments to the request. so this worked: it "should return an error if there is no correct email" do params = {:subscription => {:email => "andre"}} post "/magazine_subscriptions", params.to_json, {'ACCEPT' => "application/json", 'CONTENT_TYPE' => 'application/json'} end

Categories : Ruby On Rails

How to pass JSON from model to view and display the JSON as table in backbone js?
I don't think you need to do all that work. You simply need to fetch the collection, once the fetch is complete render the views and use a template to decide what to show or not. No need to edit the model. Have a look at the Tips and Tricks section and read about template variables. That site has some great, short articles to get started. If you're looking to create a more 'complete' app with some modules, etc, have a look at this page.

Categories : Backbone Js

ASP.NET Model binding One to Many + AJAX
In my aproach would be if a people can have many stuff and you want to use ajax you can create a partial view to edit the stuff you would send the stuff object from people to the patial view action and run partial view action on the ajax call.

Categories : Asp Net Mvc

Model Binding Postback
Asp.Net MVC require propertioes on your model in order for the model binding. Hence check your model and ensure all members are exposed as properties. Eg: You change your model to something like below. public class Poll { public Answer Answers { get; set; } }

Categories : C#

web api model binding to an interface
Look at Model Binders section here. I think it is your case.

Categories : C#

ASP.NET MVC Model binding not parsing
Looks like an encoding problem. Try using the UploadData method instead and use UTF-8 encoding: using (var wc = new WebClient()) { var data = Encoding.UTF8.GetBytes(@"{""AdobeId"":0,""FristName"":""Kasper Rune"",""LastName"":""Søgaard"",""Email"":""krus@arcanic.dk"",""OrganizationIdentification"":null,""Organization"":null,""OrganizationFull"":null}"); wc.Headers[HttpRequestHeader.Accept] = "application/json"; wc.Headers[HttpRequestHeader.ContentType] = "application/json"; byte[] result = wc.UploadData(url, "POST", data); string json = Encoding.UTF8.GetString(result); } Alternatively you could use the new HttpClient: using (var client = new HttpClient()) { client.DefaultRequestHeaders.ConnectionClose = true; var value = new { AdobeId = 0,

Categories : Json

DateTime model binding asp.net mvc
The computer will parse the date based on its region (it is set in the control panel in various places depending on the OS). If your two machines have different regional settings, there will be friction as different regions exress dates different (dd/mm/yyyy in the U.K., mm/dd/yyyy in the U.S.). You can override that setting by configuring your web.config to help with consistency. <globalization culture="en-US" uiCulture="en-US"/> Another option I would suggest is to save the value of your web form control in the universal date time format: e.g. Tue, 1 Jan 2008 00:00:00 GMT. This will be parsed correctly irrespective of your machine's region.

Categories : Asp Net Mvc

Is this by design in MVC Model Binding?
This is by design - ModelState is the highest priority value-provider for model properties, higher than even model itself. Without query string parameter, ModelState does not contain value for MyProperty, so framework uses model value. You can use ModelState.Remove("MyProperty") to ensure using model value

Categories : Asp Net Mvc

ng-model binding not working on div
Please try this, it might help https://github.com/angular/angular.js/issues/528 This is a 3 year old open issue that tons of people would like fixed. It's marked as a post-1.2-milestone and a feature rather than a bug. Seeing as Angular.js is on release 1.2.13 as of Feb 2014, it looks like no one on the team cares about this issue at the moment. As a result you'll be better off rolling your own code or sticking with a input/textarea control.

Categories : Javascript

Binding DataGridComboBoxColumn with model
You need to specify DisplayMemberPath for the ComboBox. <DataGrid name ="gridPerson" AutoGenerateColumns="False"> <DataGrid.Columns> <DataGridTextColumn Binding="{Binding Name}" Header="Person Name" /> <DataGridComboBoxColumn Header="CountryName" SelectedItemBinding="{Binding County}" SelectedValueBinding="{Binding Path=Id}" SelectedValuePath="Name" DisplayMemberPath="Name" /> </DataGrid.Columns> </DataGrid

Categories : C#

Dynamic SQL binding with MVC model
You could serialize the data (eg JSON) and return serialized as string to deserialize on the other end (wherever this ends up). If the return trypes are similar enough, you could have them all inherit from the same superclass. You could use generics (see: dynamic return type of a function)

Categories : Asp Net Mvc

Model Binding To A List
Add a Checked property on your ViewModel then bind it to a checkbox using Html.CheckBoxFor then route the values back to your controller. At the controller, you can now query all checked items using LINQ.

Categories : C#

CA2227 and ASP.NET Model Binding
I believe you would need to create a custom ModelBinder to work around this, which isn't worth it. In this case since there's reasonable benefit to break the rule go ahead and suppress it.

Categories : C#

handling dataset array as dataset in matlab like as other programs(spss,r,stata)
b = datasetfun(fun,A) applies the function specified by fun to each variable (each column) of the dataset array A. As factoran needs more than one column to perform its opertaions, it can't be used with datasetfun.

Categories : Matlab

Clone dataset > Change column type > Populate dataset
assuming you have only one table in the data set, you can do something like this. int ColumnIndex = 0; //Column index of your data you want to copy for (int i = 0; i < dataset_original.Tables[0].Rows.Count; i++) { dataset_cloned.Tables[0].Rows[i].SetField(ColumnIndex, dataset_original.Tables[0].Rows[ColumnIndex].ItemArray[0].ToString()); } in the same for loop you can copy remaining columns data

Categories : Asp Net

Why binding this list is not working on POST?
Try like this: @Html.HiddenFor(m => m[i].Stream.Id) <div class="editor-label"> @Html.CheckBoxFor(m => m[i].Selected) @Html.DisplayFor(m => m[i].Name) </div> By the way when you inspected the generated HTML of this Razor view I hope the if statement wasn't hit multiple times and inside your <form> element you had at least some inputs. Use FireBug or Chrome developer toolbar in order to inspect what exactly gets sent to the server as payload of the POST request. Also there's a problem with this continue; statement. This can potentially leave holes in the indexes that you are submitting to the server which is invalid according to the expected format of the default model binder for binding to a list. When you inspect the POST payload in Fiddler you shou

Categories : Asp Net Mvc

ASP.Net MVC Form binding with Model sample
in the Views there is a helper called Html you can use it in the view like @Html there are all things that you wanted, for example @Html.HiddenFor @Html.RadioButtonFor @Html.TextAreaFor and so on search for asp.net mvc Html helpers another smaple @Html.CheckBox("sameName") @Html.CheckBox("sameName") @Html.CheckBox("sameName") @Html.CheckBox("sameName") it will produce this html <input type="checkbox" name="sameName" /> <input type="checkbox" name="sameName" /> <input type="checkbox" name="sameName" /> <input type="checkbox" name="sameName" /> take a look at this website

Categories : Asp Net Mvc

View not binding correcty with the model
Why are you forcing the ListBox's id here: @Html.ListBoxFor(contact => contact.SelectedFonctionIds, new MultiSelectList(Model.ListeFonctions, "IdFonction", "LibelleFonction"), new { disabled = "disabled", **id="idFonctions"** }) ListBoxFor helper is supposed to generate the ListBox's id for you, and the Id should be the same as the attribute it should bind with. Shouldn't it be SelectedFonctionIds? Was the binding working before you started using the PartialView? Because from your previous question, I see that you had: @Html.ListBoxFor(contact => contact.SelectedFonctionIds, Model.ListeFonctionsSelectList, new { disabled = "disabled" }) in your View (i.e., you didn't set the id attribute).

Categories : Asp Net Mvc

Asp.Net MVC Dynamic Model Binding Prefix
I don't know why you would want to do this, but this should work. In your form on the view, have a hidden value @Html.Hidden("BindingPrefix", Model.BindingPrefix) Modify your action to the following [HttpPost] public ActionResult Search(SearchViewModel model) { UpdateModel(model, model.BindingPrefix); }

Categories : Asp Net

Angularjs dynamic binding for ng-model
Binding to attributes that don't exist yet works. You can bind to a.b.c even if $scope.a does not exists. Angular creates the objects and attributes on-the-fly. <input type="text" ng-model="a.b.c" /> But you are trying to bind to an array element that does not exist yet: <input type="text" ng-model="a.b[0].c" /> Angular would have instantiate the array and then push an empty object in it and then assign it's name. Apparently this does not work.

Categories : Angularjs

MVC 4 EF 5 ID field changing value on Model Binding
I guess this is because you are on the edit page with the id, and then you do a post and it overrides your string ID with the id from the url (routevalue). Not sure. Your code is a bit messy here some things: Label label = dbl.Labels.Where(l => l.ID == criteria.Label).FirstOrDefault(); replace with: Label label = dbl.Labels.FirstOrDefault(l => l.ID == criteria.Label); also criteria.Label is a string I guess or is it the item? You should name it LabelID. Because it is confusing^^. I think you can fix all this by renaming your ID in label class to something like LabelID or something. Then the system won t get confused with the 2 ids.

Categories : Entity Framework



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.