2
Answers

Jquery live() method Not Working In ASP.net MVC

Hello.... 
Anyone can help..
live() method Not Working i am Using jquery-1.10.2.min.js. and .live() method Not Working 1.9 Onword Version..  so How To Write This Function Now  
 
$('a.remove').live("click", function (e) {
e.preventDefault();
$(this).parent().parent().remove();
});
 
<table id="dataTable" border="0" cellpadding="0" cellspacing="0">
<tr>
<th>Category</th>
<th></th>
</tr>
@if (Model != null && Model.Count > 0)
{
int j = 0;
foreach (var i in Model)
{
<tr style="border:1px solid black">
<td>@Html.TextBoxFor(a => a[j].Category)</td>
<td>
@if (j > 0)
{
<a href="#" class="remove">Remove</a>
}
</td>
</tr>
j++;
}
}
</table>
$('a.remove').live("click", function (e) {
e.preventDefault();
$(this).parent().parent().remove();
});
Answers (2)
0
Dr.Ajay Kashyap

Dr.Ajay Kashyap

NA 455 30.4k 7y
sandeep sir ...this is my all code And I also add script FROM CDN
 
View:- 
 
@using (Html.BeginForm("CreateCategory", "CategoryAndSubCategory", FormMethod.Post, new { enctype = "multipart/form-data", @id = "category" }))
{
@Html.AntiForgeryToken()
Create Category
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
Add New
@*
@Html.LabelFor(model => model.Category, htmlAttributes: new { @class = "control-label col-md-2 required" })
@Html.EditorFor(model => model.Category, new { htmlAttributes = new { @class = "form-control", @placeholder = "Enter Category Name", @onKeyPress = "return ValidateAlphaComma(event);" } })
@Html.ValidationMessageFor(model => model.Category, "", new { @class = "text-danger" })
*@
@*
*@
@if (Model != null && Model.Count > 0)
{
int j = 0;
foreach (var i in Model)
{
@*
*@
j++;
}
}
Category IDCategory
@Html.TextBoxFor(a => a[j].CategoryId)@Html.TextBoxFor(a => a[j].Category)
@if (j > 0)
{
Remove
}
}
<!-- Inject Script Filtered -->
<!-- Inject Script Filtered -->
<!-- Inject Script Filtered -->
<!-- Inject Script Filtered -->
<!-- Inject Script Filtered -->
 
 
Controller:- 
 
[HttpGet]
public ActionResult CreateCategory()
{
List ci = new List { new CategoryViewModel { Category = "" } };
return View(ci);
}
 
 
0
Sandip Patil

Sandip Patil

NA 1.7k 77.4k 7y
For this purpose 
 

add script FROM CDN

<!-- Inject Script Filtered -->

For more details please refer:  My personal blog
 
https://sandippatilprogrammer.wordpress.com/2013/11/29/jquery-live-method/ 
 
 
Please let me know ...wheather it's found useful or not