Dear all, I have a simple asp.net mvc core application in which I have main view and partial view with strongly type models , on delete which is on partial view I want to show sweet alert (which works fine on main view but not on partial view ) below is my code , when I call the javascript method from button it says function not defined even though it is there below is my code.
I am share all code based the first approach i am sharing only partial view code with sweet alert
@section Scripts {
}
RESULT: it did not give any error in console but swal is not firing i am assure I have sweet alert reference in my _layout that is why on main view it works but in partial view it did not work.
___________________________________________________________________________________________________________Here is the second approach in which it says the function is not define in which I call the swal I am sharing the main view + partial view + controller method as shown below /
MY PARTIAL VIEW CODE :
@model web.ViewModels.mywm
@{
Layout = null;
}
List
| Type | Category | Description | Delete |
|---|---|---|---|
| @item.myitem.SubCategory | @item.myitem.Category | @item.myitem |
@section Scripts {
}
My Main View Code:
@model web.ViewModels.mywm
@using web.Classes
@section Scripts {
@* *@
}
Contorller Delete method :
[HttpPost]
public IActionResult Delete(int id)
{
try
{
var item=DbContext.ITEMS.Where(a=>a.itemid==id).FirstOrDefault();
if (item != null)
{
DbContext.ITEMS.Remove(item);
DbContext.SaveChanges();
return RedirectToAction("Index");
}
}
catch (Exception ex) {
TempData["errorMessage"] = ex.Message + "item cannot be deleted";
return View();
}
return View();
}
still swal is not firing the issue is with partial view I have checked to replace button with @HTML.ACTIONLINK AS WELL BUT STILL THE SAME SOME TIME it show no error and sometime it says javascript function is not defined with call the swal , I haev sweet alert reference in _Layout and it work for main index , secondly ignore spelling mistake from this post like model name or etc.
Local CodersPosted Aug 14, 2024, 3:38 PM
function DeleteRecord() call it in parent page or create common .js scrip file and place it into parent page and try. it will trigger the pop