TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
First Last
NA
648
71.5k
Input field with html tag - how to get it to not show the html
Sep 14 2020 6:47 PM
I have an input field that shows the html tag and also does not do what it is supposed to do. In this case, show the content in 2 lines without the html tag. (like the display only does - shown next.)
<p>reguser1p>My first edited comment.
After "My first edited comment" is entered by the User and before it is saved to the table I prepended it with the 'name of the user' surrounded with the p tag. I did this so when it is subsequently shown either for update via an input tag or display via a div tag that the "My first edited comment" goes to a 2nd line. It works for display but not for edit in an input tag.
The data in the database table that is in the model that is used.
<p>reguser1p>My first edited comment.
I have a display only field that does NOT show the html tag and does what the tag is supposed to do.
reguser2
My first comment about this new blog site.
The data in the database table that is in the model that is used.
<p>reguser2p>My first comment about
this
new
blog site.
How do I code the input field to display properly - the "My first edited comment" goes to a 2nd line?
I'm using what I use for the display only field to decode the HTML - using decode to get rid of the tags.
value=
"@Html.Raw(WebUtility.HtmlDecode(@blogComment.BlogCommentContent))"
I tried this as well - but get an error:
<div
class
=
"form-control"
id=
"@string.Format("
{0}_{1}
", "
inputEditComment
", blogComment.BlogCommentId)"
style=
"display: inline; margin-top: 27px; font-size: 13px; color: #9c9898;"
>
@Html.EditorFor(model => WebUtility.HtmlDecode(@blogComment.BlogCommentContent))
</div>
The error is:
System.InvalidOperationException: 'Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions.'
Here is the asp.net partial view (not all of it):
@
if
(blogComment.UserId == blogComment.SignedInUserId)
{
@* Can edit the input field. *@
<input type=
"text"
id=
"@string.Format("
{0}_{1}
", "
inputEditComment
", blogComment.BlogCommentId)"
class
=
"form-control"
value=
"@Html.Raw(WebUtility.HtmlDecode(@blogComment.BlogCommentContent))"
style=
"display: inline; margin-top: 27px; font-size: 13px; color: #9c9898;"
/>
<a href=
""
class
=
"editComment"
data-id=
"@blogComment.BlogCommentId"
>Savea>
<a href=
""
class
=
"deleteComment"
data-id=
"@blogComment.BlogCommentId"
> Deletea>
}
else
{
@* Display only. *@
<div style=
"margin-top: 27px; font-size: 13px; color: #9c9898;"
>
@Html.Raw(WebUtility.HtmlDecode(@blogComment.BlogCommentContent))
div>
}
Reply
Answers (
5
)
Display User image after Login in Role base MVC
How to create this div class in bootstrap?