My problem is that, I have a strongly typed view and to retain some model values. I am using hidden control in my View. But due to security purpose, I don't want hidden fields on my View.If I will not use them then on Post action I am
Do you need them on GET? If not, create a view model without the fields. Or use HTTPS
Thanks! good suggestion. I will definitely try with form collection.
But just a simple question, if I access control values in controller don't you think it would be the violation of MVC pattern. Controller shouldn't be aware controls
formcollection will not work in my case because I am not binding the model values to the form controls. So form collection will not work in my case.
In my case, I am setting few values during get request and using them during post. I am not dispalying them in my form thats why I used hidden fields.
I cannot use the session approach beacuse there is a custom validation attribute at class level where I need those hidden value fields. And I don't want to use session in my Model and Custom attribute class.
qwe123kids
All-Star
48619 Points
7957 Posts
MVP
Re: How to get rid of hidden fields in ASP.net MVC 2
Nov 24, 2010 12:24 PM|LINK
/**
And if he opens 2 browsers with same action, but with different ID ??
*/
Then Y Donot U understand 2 thigs?
1 } When Click event Ocurs then Sesion Is Going to Clear
Example
Controller
Action method()
String strvalue = Convert.toString(Session["Avinash"]);
===perform Some DatabAse Wordk===================
Clear Session
2 } U can Create A Dynamic Session NBame
Example
in view Session Name WouldSome Thing Like This
HiddenFile value with Some Dynmaic Genrated Numbner
Session["Avinash" + Dynamic_GenratedNumber] = Model.Id
Know Will retive it Will
string strvalue = Convert.TosTring(Session["Avinash + formcollection["DynamicGenretdNumber"]])
Avinash Tiwari
Remember to click “Mark as Answer” on the post, if it helps you.
sachingusain
Star
8786 Points
1702 Posts
Re: How to get rid of hidden fields in ASP.net MVC 2
Nov 24, 2010 12:31 PM|LINK
No. Not a session for each controller. Neither am I advising to put big/heavy objects in session.
Create a session object for what you need and use your discretion there.
We can only advise then it is up to the person to implement it judiciously.
Thanks.
ignatandrei
All-Star
134838 Points
21603 Posts
Moderator
MVP
Re: How to get rid of hidden fields in ASP.net MVC 2
Nov 24, 2010 01:11 PM|LINK
It will not work with 2 simultaneos actions
Just said that he does not want to use hidden fields.
qwe123kids
All-Star
48619 Points
7957 Posts
MVP
Re: How to get rid of hidden fields in ASP.net MVC 2
Nov 25, 2010 04:48 AM|LINK
Hi,
I Know 1}Will not Work in Scenario But Hidden Filed I s having
1} Dynamcially Genertaed Number
2} If number Cahnged Or Mofied That can Checked While Retreving Session Which Would Be Blank or Null
3} Compared having all Sentstive information in Hidden Filed It Havving Randomg Number Session Which Would Be Quite Secure
Compare to having Whole Model in View.
Avinash Tiwari
Remember to click “Mark as Answer” on the post, if it helps you.
dee_singh
Member
10 Points
10 Posts
Re: How to get rid of hidden fields in ASP.net MVC 2
Nov 25, 2010 06:05 AM|LINK
Hi,
Is there any other work around? I really want to avoid session variables.
Regards,
Deepti
"ASP.NET MVC" "asp.net Mvc" View Composition
mdrubaiyat
Member
27 Points
9 Posts
Re: How to get rid of hidden fields in ASP.net MVC 2
Nov 25, 2010 08:13 AM|LINK
Yes. Always try to avoid the Session as possible.
You can use Formcollection rather than Model. In collection you will find all the values
Please click 'Mark as Answer' if my reply has assisted you
-rubaiyat
ricka6
All-Star
15070 Points
2272 Posts
Microsoft
Moderator
Re: How to get rid of hidden fields in ASP.net MVC 2
Nov 25, 2010 03:19 PM|LINK
Do you need them on GET? If not, create a view model without the fields. Or use HTTPS
dee_singh
Member
10 Points
10 Posts
Re: How to get rid of hidden fields in ASP.net MVC 2
Nov 26, 2010 04:29 PM|LINK
But just a simple question, if I access control values in controller don't you think it would be the violation of MVC pattern. Controller shouldn't be aware controls
But I do understand I have other constraints too
"ASP.NET MVC" .net mvc 2
dee_singh
Member
10 Points
10 Posts
Re: How to get rid of hidden fields in ASP.net MVC 2
Nov 29, 2010 03:17 PM|LINK
formcollection will not work in my case because I am not binding the model values to the form controls. So form collection will not work in my case.
In my case, I am setting few values during get request and using them during post. I am not dispalying them in my form thats why I used hidden fields.
I cannot use the session approach beacuse there is a custom validation attribute at class level where I need those hidden value fields. And I don't want to use session in my Model and Custom attribute class.
Any other suggestion?
mdrubaiyat
Member
27 Points
9 Posts
Re: How to get rid of hidden fields in ASP.net MVC 2
Dec 02, 2010 04:02 AM|LINK
Dear dee_singh,
If you give me the sample page and controller code. Inshallah I will solve your problem ASAP
Please click 'Mark as Answer' if my suggestion has assisted you
-rubaiyat