The above JavaScript close function works except it also triggers the [HttpPost] Edit method of controller, it is just simple close current window, no post action at all, and the javascript does not call controller at all,
no sure why it also triggers the Edit method of controller, is that anything to pass the Edit method of controller?
From your description and codes, I can't reproduce your problem. Are you sure that it triggers the method when you click the colse button? or maybe somewhere else? Since you want to close the current window, why not just use window.close()?
Best Regards,
Jiadong Meng
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com
From your description and codes, I can't reproduce your problem. Are you sure that it triggers the method when you click the colse button? or maybe somewhere else? Since you want to close the current window, why not just use window.close()?
Best Regards,
Jiadong Meng
Hi Jiadong, thanks a lot for your help,
Yes, it does trigger the Edit method of controller, I have started the debug and see the code going through, this causes the problem because I have some business log may also be triggered there.
I have also tried to just use Window.close(), and when I click Close button, I got a extra popup window with the message of "The webpage you are viewing is trying to close the tab. Do you want to close this tab?" with Yes , No button under it. so user has
to click Yes button to close it, and if user click No at this point, the form validation triggered which is also not what I wanted.
Could you please show us the codes of the two views (the current window and the
separate window) and the related controller actions such as Edit, because it works fine on my side.
Best Regards,
Jiadong Meng
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com
Member
342 Points
2139 Posts
How come this javascript function to close the current window tab triggers the Edit method in con...
Oct 31, 2019 02:37 PM|Peter Cong|LINK
I am trying to open the separate window (tab) by using this:
Html.ActionLink(GlobalRes.Details, "Edit", new {id = item.Prod_ID }, new { target = "_blank" }).ToString()
This code works fine, the separate window is opened,
but I also want to add Close button to close it by this codes,
<button name="button" id="CloseBtn" class="btn btn-primary btn-sm" onclick="javascript:closewindow()">@GlobalRes.Close</button>
function closewindow() {
window.open('', '_parent', '');
window.close();
}
The above JavaScript close function works except it also triggers the [HttpPost] Edit method of controller, it is just simple close current window, no post action at all, and the javascript does not call controller at all,
no sure why it also triggers the Edit method of controller, is that anything to pass the Edit method of controller?
Thanks
All-Star
53574 Points
13316 Posts
Re: How come this javascript function to close the current window tab triggers the Edit method in...
Oct 31, 2019 04:54 PM|bruce (sqlwork.com)|LINK
to enable the close, you are opening the current window:
window.open('', '_parent', '');
this of course reloads the current page, calling your controller.
Member
342 Points
2139 Posts
Re: How come this javascript function to close the current window tab triggers the Edit method in...
Oct 31, 2019 07:46 PM|Peter Cong|LINK
It is good to k now that, do you know any better way, or simple way to avoid that based on what current codes I have now?
I also tried window.open('',"_self", ""); no luck
Thanks
Member
420 Points
158 Posts
Re: How come this javascript function to close the current window tab triggers the Edit method in...
Nov 01, 2019 07:48 AM|jiadongm|LINK
Hi Peter,
From your description and codes, I can't reproduce your problem. Are you sure that it triggers the method when you click the colse button? or maybe somewhere else? Since you want to close the current window, why not just use window.close()?
Best Regards,
Jiadong Meng
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com
Member
342 Points
2139 Posts
Re: How come this javascript function to close the current window tab triggers the Edit method in...
Nov 01, 2019 12:47 PM|Peter Cong|LINK
Hi Jiadong, thanks a lot for your help,
Yes, it does trigger the Edit method of controller, I have started the debug and see the code going through, this causes the problem because I have some business log may also be triggered there.
I have also tried to just use Window.close(), and when I click Close button, I got a extra popup window with the message of "The webpage you are viewing is trying to close the tab. Do you want to close this tab?" with Yes , No button under it. so user has to click Yes button to close it, and if user click No at this point, the form validation triggered which is also not what I wanted.
Any idea?
Member
420 Points
158 Posts
Re: How come this javascript function to close the current window tab triggers the Edit method in...
Nov 04, 2019 08:46 AM|jiadongm|LINK
Hi Peter,
Could you please show us the codes of the two views (the current window and the separate window) and the related controller actions such as Edit, because it works fine on my side.
Best Regards,
Jiadong Meng
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com