Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am developing a MVC4 application. I have an action in the controller.

It basicly takes the Id of item (here telephone number) and change the value of deleted column. So the user can not see the item and thinks that he/she deleted it. Whatever, here is the code.
C#
public ActionResult VirtualDelete(int Id = 0)
      {
          var guncelle = _telefon.Select(Id);
          guncelle.Deleted = 0;
          _telefon.Update(guncelle);
          return RedirectToAction("Profil", "Kisi", new { Id = guncelle.KisiID });
      }


On the view side I have a button, that runs the action.
HTML
<a href="@Url.Action("VirtualDelete", "Telefon", new { Id = @telefon.TelefonID })" class="btn btn-danger">
                                               
                                           </a>


The problem is that; When the user clicks on the delete button, A submission is required. Are you sure. Do you want to delete this item? If Ok, delete it, If not, dont delete... I think this is JS stuff. So I am blind of JS. Could anyone help me?

PS:I researched, however there is no solution with URL.Action.
Posted
Comments
TryAndSucceed 26-Nov-13 10:18am    
So, what do you want to achieve? You dont want to delete or dont want to change?
FoxRoot 26-Nov-13 10:24am    
It deletes. No problem. I want to achieve, first ask to user; "Are you sure? Do you want to delete this item?" If user clicks Yes, the item will be deleted. If user clicks NO, the item wont be deleted.

1 solution

There are lot of ways by which you could achieve this. Here is one of them. Obviously I would like you to understand this and expand on it! Do post if you have any questions!!

http://jsfiddle.net/76jx6/1/[^]
 
Share this answer
 
v2
Comments
FoxRoot 26-Nov-13 10:27am    
Thank you for the responce. However, I can't apply this solutions to my MVC application. It works with URL.Action. How can I use this?
Karthik. A 26-Nov-13 10:49am    
You can always replace "/some/url" w/ @Url.Action. Do you see e.preventDefault in the jquery part? When a user clicks on the link, it prevents the default action (which is redirecting the user to the delete page/action) and then displays a dialog. If and only if the user clicks on "Yes", the actual action is carried out!
FoxRoot 26-Nov-13 10:51am    
I didint understand. I have no knowledge aobut JS. So the code is so complex for me. I am in trouble
Karthik. A 26-Nov-13 10:56am    
Don't worry about it, once you replace "/some/url" to to your Url.Action call, it should just work out of the box! So unless you try, it is going to be confusing. To begin with, try to understand the sample I provided. Once you do that you will get the picture of how your page could put this to use! Read through an introduction to jquery - http://www.w3schools.com/jquery/jquery_intro.asp and then get back to my example! Let us know how it went!
FoxRoot 26-Nov-13 11:13am    
Thank you so much. I Applied the solution into my solution. One more question; How can I change the X button. I want to use Yes Or no.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900