i’d like to better understand the issue of casting object to a name vs value collection
say …just if i could do it like that
1) does the java-script needs some fine tuning ? packing the data..
2) and most important for me : What is the correct way to do the conversion from that key value Js to a Dictionary<T,T> C# ?
the Aspx / Html part
<input type="text" id="tbx_Name" value="Avi" />
<input type="text" id="tbx_City" value="TelAviv" />
<input type="text" id="tbx_Country" value="Israel" />
<select id="ChosenRandomClass" style="display:none">
<option selected="selected" value="0">(choose a random)</option>
<option value="1">random Top Beach</option>
<option value="2">random Top Center</option>
<option value="3">random Local Pub</option>
</select>
the JavaScript / jQuery part
function AddNew() {
if (!confirm("would you like to add this contact ?")) return;
var Name = $('#tbx_Name').val();
var City = $('#tbx_City').val();
var Country = $('#tbx_Country').val();
var selectedRC = $('#ChosenRandomClass option:selected').val();
var hDate = []
var param1 = { key: "Name", value: Name };
var param2 = { key: "City", value: City };
var param3 = { key: "Country", value: Country };
var param4 = { key: "SelctedClass", value: selectedRC };
hDate.push(param1);
hDate.push(param2);
hDate.push(param3);
hDate.push(param4);
// is this part necessary the data will not get to
// code behind properly without the serializing ?
var startPrt = Sys.Serialization.JavaScriptSerializer.serialize(hDate);
ajaxUpdate("addNew", startPrt);
}
the Code behind C# part
public void AddNewRecord(object startPrt)
{
Dictionary<string, string> SenthDate = new Dictionary<string, string>();
// .....etc
}
i will appreciate the correct answer
thanks for your kind help and time.
I gave your sample a try and noticed that the startPrt parameter is actually being received as an Array of Dictionary(string, object). Hence, if you make the AJAX call like this:
You can define your WebMethod like the follwoing to convert the startPrt parameter to a dictionary: