Reputation: 5545
I need to pass the data from view to controller in an mvc project.
I've seen many examples with passing to controller using Form and having a submit button.
Actually I have @foreach
to populate data like a grid in the razor view.The first field is a id
, which is a link to the respective edit page to edit the fields corresponding to that id.
i need to get the clicked id
to use it in the controller to display the corresponding edit page. Here there is no need of submit
buttons.
Also i dont want to show the id
in querystring
, as the id should be secured.
How can i do that ? Please help
Thanks,
Upvotes: 0
Views: 576
Reputation: 883
I'm not sure if you can get away without passing an Id to the Edit page to edit that specific data. You could send it out to a session or cache object. That's all I can think of off the top of my head. Using the Id is not really risking security I think, but then again, everywhere I've done any kind of edit page I've always passed the Id and never had an issue.
Upvotes: 0
Reputation: 17540
The best way to get data to the controller in MVC without a submit is to use JQuery ajax to send the request and handle the response in JavaScript. You can use a POST request so that the data is not in the query string but that does not make it any more secure. The only way to secure the data in an HTTP request is to use HTTPS/SSL.
Upvotes: 2
Reputation: 1991
You need to create a custom Routing in you globle.asax file like this
routes.MapRoute(
"Check", // Route nameRegister
"Artical", // URL with parameters
new { controller = "Artical", action = "Index", id = UrlParameter.Optional }
);
i think this will help you...
Upvotes: 0