Member_2_1242703
asked on
MVC: Sending an ID from a view to a controller and doing something with it
I have a button on a view located at: localhost:99998/MyControll er/Edit/50 17
I want to take the ID (in this case 5017)
send it to the controller action (DelRec)
then update the correlating record (5017)
How do I do this?
<input type="button" value="Delete" class="btn btn-danger" onclick="location.href='@Url.Action("DelRec", "MyController")'" />
I want to take the ID (in this case 5017)
send it to the controller action (DelRec)
then update the correlating record (5017)
How do I do this?
ASKER
Seems like this way is trying to redirect to a View called DelRec, unless I'm doing something wrong. All I want to do is run some code.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
@Mike, it is not necessary to create form just to send your id to some other action method, If you have other work to manipulate and send, then it is fine!
Just for sending id to other action method, I guess my solution will work #a42061177 !
Just for sending id to other action method, I guess my solution will work #a42061177 !
ASKER
I was not successful in getting your solution to work. As I stated earlier, it was directing my browser to a view called DelRec/ID
Furthermore, my initial request was to update a record not "Just for sending id to other action method"
I would love to know how to do this correctly as while this "add another form" method works for me now, I see this as being problematic most other times.
Furthermore, my initial request was to update a record not "Just for sending id to other action method"
I would love to know how to do this correctly as while this "add another form" method works for me now, I see this as being problematic most other times.
<input type="button" value="Delete" class="btn btn-danger" onclick="location.href='@Uthat's what your question stated!rl.Action( "DelRec", "MyController")'" />
I want to take the ID (in this case 5017)You were needed take id from edit url, and then to pass id to DelRec!
send it to the controller action (DelRec)
Anyways, best of luck!
ASKER
No other relevant solutions provided...figured it out myself
Open in new window
To get id from URL (as your current url is : localhost:99998/MyControllStore into variable [myId]
Open in new window
To pass parameter (here id) use below code (use variable [myId])Open in new window