Sie könnten jQuery verwenden, wenn Ihre Felder dynamisch erstellt werden dann Ich nehme an, Sie würden diese Felder als ein Array übergeben. Sie sollten jedem neuen Feld eine Klasse hinzufügen, damit Sie sie abrufen können.
<input class="dynamicInput" type="text"></input>
<input class="dynamicInput" type="text"></input>
<input class="dynamicInput" type="text"></input>
<button id="submit">submit</button>
<script type="text/javascript">
$(function(){
var myArray = [];
$('#submit').on('click', function(i,val){
//It will go through any input with a class "dynamicInput"
$.each($('.dynamicInput'), function(){
myArray.push($(this).val());
});
//We'll send our array to MyAction
$.post('/MyController/MyAction', myArray, function(data) {
//If your action returns a string you could handle it through "data"
console.log(data);
});
});
});
</script>
Dann die Aktion dieses Array througn eine HTTP POST-Anfrage als JavaScript-Objekt, müssen Sie es auf eine C# Array deserialisiert wird, so dass Sie es in Ihrem Server-Seite umgehen kann:
[HttpPost]
public ActionResult MyAction(FormCollection values)
{
var jsonArray = values["myArray"];
var deserializer = new JavaScriptSerializer();
var cSharpArray = deserializer.Deserialize<List<string>>(jsonArray);
//Here you will handle your array as you wish
//Finally you could pass a string to send a message to your form
return Content("Message to user");
}
Haben Sie FindControl (controlName) ausprobiert? –