I have done create,edit functionality & trying to do delete functionality but by default my page redirects to the Delete.aspx
for delete confirmation.
I want the following steps to occur when i try to delete my record. Currently i am on
index.aspx and want to stay on same page & delete the record from database.
Image 1
Image 2
Image 3
I don't want this deletion from URL. for ex. http://localhost:53402/Project/Delete/11, it will be very easy for anyone to delete any record giving id.
You have to do it over some sort of id, there isn't any other way.
If you don't want users manipulating the URL, you need some sort of login/permission system.
Try this with jquery:
If you are trying to achieve a true MVC, as your question implies, the event transaction would submit to a controller, like index.aspx - that controller would have an event that specifies the current view page that you are sitting in, like
event="displayGui" would include the view file "frmCreate.aspx" or "frmEdit.aspx"
when the view file(s) "frmCreate.aspx" or "frmEdit.aspx" submits, it calls another event in the controller like
event="submitAndConfirm"
Event submitAndConfirm would include instructions for handling the delete action, by including a file called actDelete.aspx. When the work was complete by the actDelete.aspx, the controller would call back event="displayGui".
This is a conceptual example and would need aspx specific implementation.
If you don't want users to guess the id, use Guid instead of int
http://localhost:53402/Project/Delete/30D4AAF1-3CF1-4514-A025-2DDE1C770CD5
in order to perform a delete using javascript and a pop-up, you need to: 1)Create an action in the controller like the following:
By decorating the action method with the [HttpPost] annotation, you avoid the undesired behaviour of a user typing the URL /Home/Delete/1 because only a POST will invoke the action.
2)If you delete-item is part of a list of items, you need to bind to your items in the View a sort of id, using the custom HTML5 attributes, like the following:
3)Using jQuery, as an example, bind to your delete button(s) in the page a pop-up on click
We need to specify a callback that will handle the delete button click
4)Using for example jQuery UI dialog component:
Create HTML for your pop-up text
Handle the delete button click and bind the dialog to the html text so that the popup will tell the user what you want
So, we get the id of the button
where "this" is the HTML element which caused the event to fire using
The below row is actually where we ask the Controller to execute the delete action, and we use the id of the record
5) Because the jQuery post is asynchrounous, we need a callback to handle the result
That's it... keep in mind that it's just an example and I'm using jQuery dialog component, while you could use something different.