0
我使用jQuery的tempate來建立我的表。當用戶點擊我的表格中的一個單元格時,我在此單元格上添加屬性「名稱」。我如何才能將單元格td導入控制器?
我想檢索哪個單元格被點擊,並與哪個值,但我不成功,以檢索我的價值細胞到控制器asp mvc。 我使用FormCollection,但我沒有找到我的單元格TD,我也試着request.form [「cellTd」]但它不工作。 在我的控制器中,cell等於null,而form不包含元素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"];
}
}
@Ropstah,我必須多表與multiselected在我的控制器發送。用簡單的輸入發送信息是不可能的?否則,我創建一個功能,發送所有具有名稱的元素... – Zoners 2012-04-16 14:25:12
您希望在控制器中獲得什麼值? – Ropstah 2012-04-16 16:01:49
@Ropstah我想收到所有填充了屬性名稱的元素。我有不同的價值觀到我的單元格,我有一個簡單的文本(字符串或整數)或一個應答器img(我添加一個屬性'說明'在舞臺上img知道圖像的價值) – Zoners 2012-04-17 08:31:50