jquery のテンプレートを使用してテーブルを作成します。ユーザーがテーブルの 1 つのセルをクリックすると、このセルに属性「name」が追加されます。
クリックされたセルと値を取得したいのですが、値のセルをコントローラーasp mvcに取得できません。FormCollection を使用していますが、セル td が見つからず、request.form["cellTd"] も試しましたが、うまくいきません。私のコントローラーでは、セルはnullに等しく、フォームには要素cellTdが含まれていません。
ご協力いただきありがとうございます。
私の見解:
@using (Html.BeginForm("Action", "Test", FormMethod.Post ))
{
<div id="TableToFill"></div>
<button id="send" value="send" name="btn" type="submit">send</button>
}
私のテンプレート:
<script id="TableTemplate" type="text/x-jquery-tmpl">
<table class="Table">
<tbody class="BodyTable">
{{each list}}
<tr class="Item">
<td description="Standard${Name}" >${this.Value}</td>
{{if $index == 0}}
<td ><input description="high${Name}" value="" type="text" /></td>
{{/if}}
</tr>
{{/each}}
</tbody>
</table>
</script>
私のコードjquery
<script type="javascript">
$.getJSON("getTable", params, function (items) {
$("#TableTemplate").tmpl(items).appendTo("#TableToFill");
});
$(".Table tbody .Item td").click(function(){
$(this).attr("name","cellTd");
});
</script>
私のコントローラー
public class TestController : controller
{
public ActionResult(FormCollection form)
{
String cell=Request.Form["cellTd"];
}
}