// GET: /Account/HairAccountMenuAdvertising/
[Authorize]
public ActionResult HairAccountMenuAdvertising(string accountmenu, int? partnerdeleteid, int? partnernonvisibleid, int? partnervisibleid, int? page)
{
if (partnerdeleteid != null)
{
Partner partnerdelete = db.Partners.Find(partnerdeleteid);
if (!User.IsInRole("Admin"))
{
// How to chek if user id is the one of the partner
var str = User.Identity.GetUserId();
if (!db.Partners.Any(m => m.UserId == str && m.PartnerId == partnerdelete.PartnerId))
{
return RedirectToAction("NotFound", "Home");
}
}
//Set the Partner to delete
partnerdelete.PartnerVisible = false;
partnerdelete.PartnerDelete = true;
db.Entry(partnerdelete).State = EntityState.Modified;
db.SaveChanges();
}
if (partnernonvisibleid != null)
{
Partner partnernonvisible = db.Partners.Find(partnernonvisibleid);
if (!User.IsInRole("Admin"))
{
// How to chek if user id is the one of the partner
var str = User.Identity.GetUserId();
if (!db.Partners.Any(m => m.UserId == str && m.PartnerId == partnernonvisible.PartnerId))
{
return RedirectToAction("NotFound", "Home");
}
}
//Set the Partner to nonvisible
partnernonvisible.PartnerVisible = false;
db.Entry(partnernonvisible).State = EntityState.Modified;
db.SaveChanges();
}
if (partnervisibleid != null)
{
Partner partnervisible = db.Partners.Find(partnervisibleid);
if (!User.IsInRole("Admin"))
{
// How to chek if user id is the one of the partner
var str = User.Identity.GetUserId();
if (!db.Partners.Any(m => m.UserId == str && m.PartnerId == partnervisible.PartnerId))
{
return RedirectToAction("NotFound", "Home");
}
}
//Set the Partner to nonvisible
partnervisible.PartnerVisible = true;
db.Entry(partnervisible).State = EntityState.Modified;
db.SaveChanges();
}
var partners = db.Partners as IQueryable<Partner>;
var userstr = User.Identity.GetUserId();
partners = partners.Where(r => r.UserId == userstr);
//Not hidden by admin and Not deleted by user
//partners = partners.Where(r => r.PartnerVisible.Equals(true));
partners = partners.Where(r => r.PartnerDelete.Equals(false));
//SORTING
partners = partners.OrderBy(r => r.PartnerTitle);
//FIRST 250
partners = partners.Take(250);
//Pagination
int pageSize = 25;
int pageNumber = (page ?? 1);
return PartialView(partners.ToPagedList(pageNumber, pageSize));
}
it looks like the second time i hit the javascripts are npot working anymore
The design overwrites, what looks like, a paged list UI. This approach breaks the JavaScript/jQuery event handlers that were set when the page initially loaded.
I recommend dropping the AJAX form for a full post back. The alternative fixing the general design which will include learning AJAX/JavaScript basics.
Again, use a full post back rather than AJAX. A full post back reloads your JavaScript application.
grafic.web
on ajax form sent success than reload all the javascripts..
any guess?
No need to guess when you have the reference documentation. Sure, you can rerun the same scripts but it causes a memory leak and considered a bad practice.
on ajax form sent success than reload all the javascripts..
any guess?
typically the issue is that the script have bound event handlers to dom elements and the ajax has repacked these elements (so they are not bound anymore). you need to go thru each script and review the bindings and rerun. for some they will have a rebind
/ reinit command, some you will need to recall init. it all depends on the libraries you are using.
additionally if any of these libraries don't use jquery binding (vanilla js), you will have a memory leak as these elements will not be released. you should call the libraries unbind command before calling the new bind.
Member
327 Points
1767 Posts
why ajax form Ajax.BeginForm does not work second time i hit the link
Dec 01, 2020 01:19 PM|grafic.web|LINK
I have a list of items,
in this list i can activate and desactivate eaach item,
the first time i click on activate all works but when the container is reloaded i cannot use anymore the ajax form for the others items..
why?
code in first page index.html:
on partial view
controller
it looks like the second time i hit the javascripts are npot working anymore
any help?
All-Star
52091 Points
23207 Posts
Re: why ajax form Ajax.BeginForm does not work second time i hit the link
Dec 01, 2020 01:51 PM|mgebhard|LINK
The design overwrites, what looks like, a paged list UI. This approach breaks the JavaScript/jQuery event handlers that were set when the page initially loaded.
I recommend dropping the AJAX form for a full post back. The alternative fixing the general design which will include learning AJAX/JavaScript basics.
Member
327 Points
1767 Posts
Re: why ajax form Ajax.BeginForm does not work second time i hit the link
Dec 01, 2020 02:03 PM|grafic.web|LINK
i was thinking to reload all the javascritps...
how to ahive this?
on ajax form sent success than reload all the javascripts..
any guess?
All-Star
52091 Points
23207 Posts
Re: why ajax form Ajax.BeginForm does not work second time i hit the link
Dec 01, 2020 02:22 PM|mgebhard|LINK
Again, use a full post back rather than AJAX. A full post back reloads your JavaScript application.
No need to guess when you have the reference documentation. Sure, you can rerun the same scripts but it causes a memory leak and considered a bad practice.
All-Star
57834 Points
15485 Posts
Re: why ajax form Ajax.BeginForm does not work second time i hit the link
Dec 01, 2020 04:44 PM|bruce (sqlwork.com)|LINK
typically the issue is that the script have bound event handlers to dom elements and the ajax has repacked these elements (so they are not bound anymore). you need to go thru each script and review the bindings and rerun. for some they will have a rebind / reinit command, some you will need to recall init. it all depends on the libraries you are using.
additionally if any of these libraries don't use jquery binding (vanilla js), you will have a memory leak as these elements will not be released. you should call the libraries unbind command before calling the new bind.