question

AhmedBahgat-0700 avatar image
0 Votes"
AhmedBahgat-0700 asked AhmedBahgat-0700 commented

.Net 5 and Web MVC page question

Hello Experts

I am all new to this and real stumbled with an issue that I am not even sure would be achievable or not

I have a Web page designed with what is mentioned in the title, it is only one page that shows a few input boxes to fill in, I need to set the value of one of those boxes and lock it so the user cannot change it, let's assume the url for this page is

https://aaa.azurewebsites.net/Registration/Create

My idea is to pass the value of that input box in the url as the {id?], so the url will become something like

https://aaa.azurewebsites.net/Registration/Create?myvalue

So how can I set the input box value to myvalue in the url and then lock it so the user cannot change

Is that possible? and if so how can I do that please. this is really important for covid-19 testing which is currently spreading widely in NSW Australia and I need to track the test registrations via that input box

Cheers

dotnet-csharpdotnet-visual-basicdotnet-aspnet-core-mvc
· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Set the input to read only.

Or use a hidden field rather a text input if you want to take advantage of form state management. Then to display the value, just write the value to the HTML like below.

 <div>
    @Model.MyReadOnlyProperty
 </div>

0 Votes 0 ·

Hello mate

Thanks for the reply and appreciate the hint for the readonly, but how do I set the value of the input box to the part of the url, i.e the parameter in the URL?

Cheers

0 Votes 0 ·
AgaveJoe avatar image AgaveJoe AhmedBahgat-0700 ·

In web applications parameters can be passed in the URL (GET) or in the body of an HTTP message (POST). If the URL contains an ID parameter then there is little reason to add the same data to a form input.

If the parameter data is sensitive then the data should not be in the URL or an input unless it is encrypted as explained in Bruce-SqlWork's post. A better option might be to store the data on a server in the user's session or in a table with the user's id. Anyway, URL parameters, input fields, session, and database tables are all forms of state management. The following link explains the state management features available in .NET 5. Pick an option that best fits your requirement(s). By the way, state management is a problem that must be solved in every web application.

Session and state management in ASP.NET Core


0 Votes 0 ·
Show more comments
Bruce-SqlWork avatar image
0 Votes"
Bruce-SqlWork answered AhmedBahgat-0700 commented

If you don’t want your site hackable, you should encrypt the hidden value. If you want to display the value also, use a styled span or read only input.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello mate

Thanks for the reply, but how do I set the value of the input box to the part of the url, i.e the parameter in the URL?

Cheers

0 Votes 0 ·
AgaveJoe avatar image
0 Votes"
AgaveJoe answered AhmedBahgat-0700 commented

The URL you've shared is incorrect. Querystring parameters are located after the "?" and consist of a name and a value.


 https://crsweb.azurewebsites.net?id=1

MVC has the concept of a route parameter where the parameter is part of the URL which matches a pattern. The default pattern is an id at the end of the URL.

 https://crsweb.azurewebsites.net/controller/action/1

Your best option is to go through a beginning level tutorial which covers these fundamentals.

Get started with ASP.NET Core MVC
Routing in ASP.NET Core


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello mate

I do understand that I need to go through the beginner level tutorial despite my over 35 years of VB desktop development experience, but unfortunately I don't have time to do that at the age of 56 and also due to my health and most importantly I am running out of time needed to for the page to be delivered, so I realized quickly that this is way beyond my abilities and even the ability for an expert to explain it in a comment or two, so I took the decision to hire a free lancer from freelancer.com and amazingly he did it in half an hour and it only costed me A$35 which is a bargain considering the circumstances, all good now and it live an working as I want it to work

You are right concerning the syntax of the embedded single Query string I had, It should be ?id= whatever, but that was not really my main problem and looking now at the project and how the freelancer did it, it is really simple but again it would have not been simple to me, the project is mine and I created everything and I just needed that bit of QueryString to deal with

Now in my free time I promise you that I will certainly go through the beginners level tutorial in great details but only for curiosity not really to make my living. I do love programming and almost wished that I know every language in that field

Cheers and al the best and thanks to everyone who replied

0 Votes 0 ·