Question hidden one of the attribute

LasG

Member
Joined
Nov 14, 2019
Messages
7
Programming Experience
Beginner
Hi there, could you tell me how to hidden one of the attribute in cshtml, so it doesn't show up on inspect element

ex :
before : <span id="1" data-customeID="2">text</span>
after : <span id="1">text</span>

Thank you
 
I don't understand why this is a C# question, or why it is even under VS.NET General Discussion. Is this for WebForms? MVC? Or is this just a vanilla HTML question?
 
I don't understand why this is a C# question, or why it is even under VS.NET General Discussion. Is this for WebForms? MVC? Or is this just a vanilla HTML question?
This question about asp.net mvc project, and i'am using html for client side,
this first time to me asking a question at online forum,
sorry for my bad english
 
I see. Hopefully one of the admins will move this topic under ASP.NET MVC to make it clearer for future readers.

Anyway, why is the attribute data-customeID in the CSHTML in the first place?
Is there something that client side that needs it? If it is needed client side, then what will happen to your client side JavaScript if it can't find that attribute?

If it only needed server side, why can't the service side code just use the id attribute?

Anyway, just doing a brain dump of what comes to mind about how I would deal with this issue if I were in your shoes:
  • Use my own custom RazorViewEngine where my renderer will strip away the data-customeID attributes.
  • Just encrypt the value in data-customeID so that it is opaque to the user. The can see it but doesn't make sense to them readily.
 
You can't do that. If there is something secret which the rendering browser engine is not meant to render, then you should not be including it in your model. Simple as that. If such values need to be secret, then they should be stored in your database or on a server side code file instead. If we could all hide certain elements from the DOM, none of us would be browsing the internet any more, due to security reasons.
 
I see. Hopefully one of the admins will move this topic under ASP.NET MVC to make it clearer for future readers.

Anyway, why is the attribute data-customeID in the CSHTML in the first place?
Is there something that client side that needs it? If it is needed client side, then what will happen to your client side JavaScript if it can't find that attribute?

If it only needed server side, why can't the service side code just use the id attribute?

Anyway, just doing a brain dump of what comes to mind about how I would deal with this issue if I were in your shoes:
  • Use my own custom RazorViewEngine where my renderer will strip away the data-customeID attributes.
  • Just encrypt the value in data-customeID so that it is opaque to the user. The can see it but doesn't make sense to them readily.
I'll try to search about RazorViewEngine to solve my issue for the first, thank you for the solution
 
What was posted by Skydiver is not the solution, its a technique to disguise the problem. As I already told you, if you have values being rendered to the client side, then you need to change your model to undo that. Prevention is the solution.

Let me put it this way. Why do you have values being shown to the DOM if they are not meant to be there?
 
You can't do that. If there is something secret which the rendering browser engine is not meant to render, then you should not be including it in your model. Simple as that. If such values need to be secret, then they should be stored in your database or on a server side code file instead. If we could all hide certain elements from the DOM, none of us would be browsing the internet any more, due to security reasons.
thank you for the explanation before, but for this section "If we could all hide certain elements from the DOM, none of us would be browsing the internet any more, due to security reasons. " I don't understant what you mean
 
What was posted by Skydiver is not the solution, its a technique to disguise the problem. As I already told you, if you have values being rendered to the client side, then you need to change your model to undo that. Prevention is the solution.

Let me put it this way. Why do you have values being shown to the DOM if they are not meant to be there?
we need this value as parameter to using in another controller
 
So you mean to tell me the controller actually goes and parses the .CSHTML of the view? That is a broken implementation. That is beyond broken. That is a complete misuse of the MVC pattern. You need to pass that information around in the model, not in the view.
 
So you mean to tell me the controller actually goes and parses the .CSHTML of the view? That is a broken implementation. That is beyond broken. That is a complete misuse of the MVC pattern. You need to pass that information around in the model, not in the view.
yeah i knew that we have to pass information / data to Model, but that information we got from view.cshtml (data-customeID)
 
Then your model as a whole is broken and needs to be rewritten. Completely rewritten.
we using model to access database, after we got the data from database, we parse it to the controller and return it to the view.
maybe you can give some of good example, so i can finish my issue.

Thank you
 
maybe you can give some of good example, so i can finish my issue.
Are you going to pay me for this work?

As of yet, you haven't shown no code to show how you did what you did, and maybe if you did, somebody might be willing to give you some pointers.
 

Latest posts

Back
Top Bottom