OKだから、テーブルにデータを表示して、このチュートリアルのように削除オプションを作成しました
http://ricardocovo.com/2010/09/02/asp-mvc-delete-confirmation-with-ajax-jquery-ui-dialog/
しかし、今私は質問があります。どうすれば正しい行から名前を取得して、このようなものを書くことができますか?
本当に「商品名」を削除しますか
OKだから、テーブルにデータを表示して、このチュートリアルのように削除オプションを作成しました
http://ricardocovo.com/2010/09/02/asp-mvc-delete-confirmation-with-ajax-jquery-ui-dialog/
しかし、今私は質問があります。どうすれば正しい行から名前を取得して、このようなものを書くことができますか?
本当に「商品名」を削除しますか
彼は Web フォームではなく ASP.NET MVC について尋ねたと思うので、コードは次のようになります。
ビューは
<table id="table">
<tr>
<td>Id</td>
<td>Name</td>
<td> </td>
</tr>
@foreach(var item in Mode.Items) {
<tr>
<td>@item.Id</td>
<td>@item.Name</td>
<td><button class="deleted-link" value="Delete">delete</button></td>
</tr>
}
</table>
<div id="delete-dialog" title="Confirmation">
</div>
ビューのJqueryスクリプトは
$(function(){
//alert($('.deleted-link'));
$('.deleted-link').each(function(){
$(this).click(function(data){
var id = $(this).parent().parent().find('td :first').html();
$('#delete-dialog').html('<p>Are you sure you want to delete the item with id = {' + id + '} ?</p>');
$('#delete-dialog').dialog('open');
});
});
$('#delete-dialog').dialog({
autoOpen: false, width: 400, resizable: false, modal: true, //Dialog options
buttons: {
"Continue": function () {
$(this).dialog("close");
},
"Cancel": function () {
$(this).dialog("close");
}
}
});
});
コード例はhttp://jsfiddle.net/SVgEL/にあります。
この助けを願っています。
モデルをビューに渡して名前を表示するのはどうですか? コメントを追加できません。回答スペースに投稿して申し訳ありません。モデルを渡したくない場合は、いつでも名前をパラメータとしてテーブル ビューから削除関数に渡すことができます。
このようなことを試すことができます
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
ImageButton imb = (ImageButton)e.Row.FindControl("deleteButton");
string recordName = e.Row.Cells[3].Text;
imb.OnClientClick = "return confirm('Are You sure Want to Delete the record:- "+ recordName.ToUpper()+" ? ');";
}
}
ボタン付き通常クリックイベント
<a href="url_to_delete" onclick="return confirm('Are you sure want to delere');">Delete</a>
すでにjQueryを使用していると仮定して、これをチェックしてください:
<script type="text/javascript">
function removeCar(theLink) {
var theTR = $(theLink).parents('tr');
var model = $(theTR).children('td._model').html();
var theConfirm = confirm("Are you sure you want to remove " + model + "?");
if (theConfirm == true)
$(theTR).remove();
}
</script>
<table>
<thead>
<tr>
<th>Make</th>
<th>Model</th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>Audi</td>
<td class="_model">A3</td>
<td><a href="#" onclick="removeCar(this); return false;">Remove</a></td>
</tr>
<tr>
<td>Audi</td>
<td class="_model">A4</td>
<td><a href="#" onclick="removeCar(this); return false;">Remove</a></td>
</tr>
<tr>
<td>Audi</td>
<td class="_model">A5</td>
<td><a href="#" onclick="removeCar(this); return false;">Remove</a></td>
</tr>
</tbody>
</table>