Questions tagged [mvchtmlstring]
32 questions
69
votes
4 answers
How to concatenate several MvcHtmlString instances
I have some doubts about how to concatenate MvcHtmlString instances because of this information found in MSDN :
MvcHtmlString Class Represents an HTML-encoded string that
should not be encoded again
Do I risk that strings are HTML-encoded twice…

M4N
- 94,805
- 45
- 217
- 260
12
votes
3 answers
TagBuilder.MergeAttributes does not work as expected
I am trying to make a HtmlHelper and I need to allow users to add their own custom attributes to the html tag.
I tried to do this using the TagBuilder class, but it seems that instead of merging the attributes, it just replaces them.
This is what I…

Catalin
- 11,503
- 19
- 74
- 147
11
votes
5 answers
Building HtmlStrings in ASP.NET MVC
I have an extension method that needs to return an HtmlString. The method has a loop which will build the HtmlString, however the HtmlString object has no Append method and does not allow concatenation using the + operator so I am not sure how I…

Judo
- 5,167
- 3
- 24
- 34
6
votes
1 answer
How to load a partialview and store it in a variable to be used in javascript?
I have a prtialview using a model to create a dropdown list.
In my main view I create the partialview html string to use it in javascript functions later.
View:
@model SomeViewModel
@{
var devicesDropDown = @Html.Partial("_DropDown",…

Forough
- 262
- 4
- 20
4
votes
1 answer
Convert PartialView Html to String for ITextSharp HtmlParser
I've got a partial view, i'm trying to use ITextSharp to convert the html to pdf. How can I convert the html to string so I can use ItextSharps HtmlParser?
I've tried something like this with no luck...any ideas?:
var contents =…

newbie_86
- 4,520
- 17
- 58
- 89
4
votes
1 answer
Stack Overflow Exception in MVcHtmlString
I have created my own Html Helper which adds red asterisks to any required field.
It successfully works with both
@Html.myLabelFor(model => model.Description)
//and
@Html.myLabelFor(model => model.Description, new { /*stuff*/ })
However, some of…

Vadzim Savenok
- 930
- 3
- 14
- 37
2
votes
1 answer
AJAX Post URL Cannot be Resolved (500) if String Includes HTML Tags
I'm trying to take the contents of a TinyMCE wysiwyg and post it to a controller function for database insertion. This setup will always display Failed to load resource: the server responded with a status of 500 (Internal Server Error) citing my…

AJH
- 365
- 1
- 4
- 18
2
votes
2 answers
Using MvcHtmlString with jQuery templates - what's the correct razor syntax?
I have such jQuery template:
And I use it in such way:
…

DevDav
- 346
- 1
- 5
- 17
2
votes
1 answer
ASP.NET MVC - How can I build an HtmlHelper that doesn't need to be Wrapped in MvcHtmlString?
When I use the build in Html Helpers, I can simply write the following.
@Html.Actionlink(bla)
But when I write my own Html Helpers, I need to block the encoding by wrapping it in a MvcHtmlString
@MvcHtmlString.Create(Html.CustomPager(bla))
Is…

Chase Florell
- 46,378
- 57
- 186
- 376
1
vote
1 answer
Passing two arguments into three parametred method?
How is it working when im passing only 2 arguments
List.cshtml
@Html.PageLinks(Model.PagingInfo, x => Url.Action("List", new { page = x }))
Into this method?
PagingHelpers.cs
public static MvcHtmlString PageLinks(this HtmlHelper html,
…

nhx
- 33
- 4
1
vote
2 answers
MVC SelectList vs MultiSelectList
In MVC, SelectList derives from MultiSelectList. I can't tell a difference between them though. For both, I have to tell it to select multiple items (I expected to not have to do this since the name has "multi" in it).
If you substitute…

Zachary
- 11
- 1
- 2
1
vote
1 answer
MvcHtmlString.Create() vs new MvcHtmlString()
I see two common ways of creating an MvcHtmlString.
var htmlStr = MvcHtmlString.Create(str);
and
var htmlStr = new MvcHtmlString(str);
Is there any difference between the two?
Can I use them both interchangeably?
Is there every any reason to…

Martin Hansen Lennox
- 2,837
- 2
- 23
- 64
1
vote
1 answer
Return HtmlString From Model & Display Within View
Let me preface this by saying that I know that I can use HTML.Raw() to display HTML contained in a string. However, I believe that the purpose of MVC is to separate the code logic and to allow front end developers to focus on UI and not logic.…

Eric K
- 689
- 9
- 26
1
vote
3 answers

JayAr
- 441
- 1
- 5
- 19
1
vote
2 answers
Using HTML in a String
In my application I have to use a some HTML stuff in a string. But HTML is not working as intended. I have to use that string (Text) to send as an email. The sequence I required of HTML is:
Title (in the center)
Image (in the center)
Description…

Usama Sarwar
- 8,922
- 7
- 54
- 80