Rectangle 27 117

This is possible to achieve inside a helper file with the @functions syntax but if you want the razor-style readability you are referring to you will also need to call a regular helper to do the HTML fit and finish.

Note that functions in a Helper file are static so you would still need to pass in the HtmlHelper instance from the page if you were intending to use its methods.

@MyHelper.DoSomething(Html, m=>m.Property1)
@MyHelper.DoSomething(Html, m=>m.Property2)
@MyHelper.DoSomething(Html, m=>m.Property3)
@using System.Web.Mvc;
@using System.Web.Mvc.Html;
@using System.Linq.Expressions;
@functions
{
    public static HelperResult DoSomething<TModel, TItem>(HtmlHelper<TModel> html, Expression<Func<TModel, TItem>> expr)
    {
        return TheThingToDo(html.LabelFor(expr), html.EditorFor(expr), html.ValidationMessageFor(expr));
    }
}
@helper TheThingToDo(MvcHtmlString label, MvcHtmlString textbox, MvcHtmlString validationMessage)
{
    <p>
        @label
        <br />
        @textbox
        @validationMessage
    </p>
}
...

You do NOT have to make the method static, and thus you also do NOT need to pass your Html/Url/Model etc

@Sheepy, that's only half true. You are correct you can make them non-static, but you only get System.Web.WebPages.Html.HtmlHelper rather than System.Web.Mvc.HtmlHelper. There's an excellent chance that the WebPages version will not be suitable for you, since most extension methods are written against System.Web.Mvc.HtmlHelper. Furthermore, there is no Url property, and UrlHelper requires a RequestContext which is unavailable in the WebPages version. All in all you're probably going to have to pass in the Mvc HtmlHelper.

the helper must be part of App_Code Folder ??

{MyMvcProject}\App_Code`. It doesn't work as advertised when you place it elsewhere. The error *Cannot access non-static method 'TheThingToDo' in static context* disappears when you move
App_Code
DoSomething
@MyHelper.DoSomething(..)
MyHelper

asp.net mvc - Is it possible to create a generic @helper method with R...

asp.net-mvc generics asp.net-mvc-3 razor
Rectangle 27 1

The @placeholder syntax tells the razor engine that you want to assign a value to an html attribute on the element that will be rendered by the helper. As such, if you needed to set a class to the textbox as well, your anonymous type would change to:

new { @placeholder = "First name", @class = "BoldText" }

As for why you use @, the @ allows you to use reserved keywords as variable names. If you tried to use

class = "BoldText"

you would receive a runtime error in your view since class is a reserved keyword in C#. The prefacing @ ensures that this doesn't happen and is considered a "best practice". The @ would only be necessary before class, not placeholder.

Yeah, but why the @?

@Nicolas : The @ sign is needed if you use a reserved word (keyword). Otherwise you would get a compilation error. Although, "placeholder" is no keyword, so it is not needed in this case.

@Styxxy in this case you'd receive a runtime exception, not a compilation error since this is in a razor view.

c# - ASP.NET MVC HtmlHelper Razor Syntax - Stack Overflow

c# asp.net asp.net-mvc asp.net-mvc-4 razor
Rectangle 27 40

I've come up with a chainable HtmlAttribute class and some Html Extension methods to allow the Razor syntax below:

<ul> 
    @foreach (var mi in items) { 
    <li @Html.Css("selected", mi.Selected)> 
        <a href="@mi.Href" @Html.Attr("title", mi.Title)>@mi.Text</a> 
    </li> 
    } 
</ul>

Here is the HtmlAttribute class:

public class HtmlAttribute : IHtmlString     
{
    private string _InternalValue = String.Empty;
    private string _Seperator;

    public string Name { get; set; }
    public string Value { get; set; }
    public bool Condition { get; set; }

    public HtmlAttribute(string name)
        : this(name, null)
    {
    }

    public HtmlAttribute( string name, string seperator )
    {
        Name = name;
        _Seperator = seperator ?? " ";
    }

    public HtmlAttribute Add(string value)
    {
        return Add(value, true);
    }

    public HtmlAttribute Add(string value, bool condition)
    {
        if (!String.IsNullOrWhiteSpace(value) && condition)
            _InternalValue += value + _Seperator;

        return this;
    }

    public string ToHtmlString()
    {
        if (!String.IsNullOrWhiteSpace(_InternalValue))
            _InternalValue = String.Format("{0}=\"{1}\"", Name, _InternalValue.Substring(0, _InternalValue.Length - _Seperator.Length));
        return _InternalValue;
    }
}

Extra info: The "seperator" is used to chain together multiple values for an attribute. This can be useful for multiple css class names (use a space) or perhaps use String.Empty to build an value dependant on multiple conditions (by using the .Add() method)

And here are the Html Extension helper methods:

public static class Extensions
{
    public static HtmlAttribute Css(this HtmlHelper html, string value)
    {
        return Css(html, value, true);
    }

    public static HtmlAttribute Css(this HtmlHelper html, string value, bool condition)
    {
        return Css(html, null, value, condition);
    }

    public static HtmlAttribute Css(this HtmlHelper html, string seperator, string value, bool condition)
    {
        return new HtmlAttribute("class", seperator).Add(value, condition);
    }

    public static HtmlAttribute Attr(this HtmlHelper html, string name, string value)
    {
        return Attr(html, name, value, true);
    }

    public static HtmlAttribute Attr(this HtmlHelper html, string name, string value, bool condition)
    {
        return Attr(html, name, null, value, condition);
    }

    public static HtmlAttribute Attr(this HtmlHelper html, string name, string seperator, string value, bool condition)
    {
        return new HtmlAttribute(name, seperator).Add(value, condition);
    }
}

Let me know if they are of use.

Hi Lee, can you give me a clue on where to put these classes in an MVC project, and how/where to reference them?

asp.net mvc - How to concisely create optional HTML attributes with ra...

asp.net-mvc razor viewengine
Rectangle 27 40

I've come up with a chainable HtmlAttribute class and some Html Extension methods to allow the Razor syntax below:

<ul> 
    @foreach (var mi in items) { 
    <li @Html.Css("selected", mi.Selected)> 
        <a href="@mi.Href" @Html.Attr("title", mi.Title)>@mi.Text</a> 
    </li> 
    } 
</ul>

Here is the HtmlAttribute class:

public class HtmlAttribute : IHtmlString     
{
    private string _InternalValue = String.Empty;
    private string _Seperator;

    public string Name { get; set; }
    public string Value { get; set; }
    public bool Condition { get; set; }

    public HtmlAttribute(string name)
        : this(name, null)
    {
    }

    public HtmlAttribute( string name, string seperator )
    {
        Name = name;
        _Seperator = seperator ?? " ";
    }

    public HtmlAttribute Add(string value)
    {
        return Add(value, true);
    }

    public HtmlAttribute Add(string value, bool condition)
    {
        if (!String.IsNullOrWhiteSpace(value) && condition)
            _InternalValue += value + _Seperator;

        return this;
    }

    public string ToHtmlString()
    {
        if (!String.IsNullOrWhiteSpace(_InternalValue))
            _InternalValue = String.Format("{0}=\"{1}\"", Name, _InternalValue.Substring(0, _InternalValue.Length - _Seperator.Length));
        return _InternalValue;
    }
}

Extra info: The "seperator" is used to chain together multiple values for an attribute. This can be useful for multiple css class names (use a space) or perhaps use String.Empty to build an value dependant on multiple conditions (by using the .Add() method)

And here are the Html Extension helper methods:

public static class Extensions
{
    public static HtmlAttribute Css(this HtmlHelper html, string value)
    {
        return Css(html, value, true);
    }

    public static HtmlAttribute Css(this HtmlHelper html, string value, bool condition)
    {
        return Css(html, null, value, condition);
    }

    public static HtmlAttribute Css(this HtmlHelper html, string seperator, string value, bool condition)
    {
        return new HtmlAttribute("class", seperator).Add(value, condition);
    }

    public static HtmlAttribute Attr(this HtmlHelper html, string name, string value)
    {
        return Attr(html, name, value, true);
    }

    public static HtmlAttribute Attr(this HtmlHelper html, string name, string value, bool condition)
    {
        return Attr(html, name, null, value, condition);
    }

    public static HtmlAttribute Attr(this HtmlHelper html, string name, string seperator, string value, bool condition)
    {
        return new HtmlAttribute(name, seperator).Add(value, condition);
    }
}

Let me know if they are of use.

Hi Lee, can you give me a clue on where to put these classes in an MVC project, and how/where to reference them?

asp.net mvc - How to concisely create optional HTML attributes with ra...

asp.net-mvc razor viewengine
Rectangle 27 12

It is actually razor syntax to tell that we are starting to write c# code, if your don't put @ it will be considered as plain text so you need to put @ sign before writing c# code in the view and in html helper method you don't need to put semicolon in front of then it is razor syntax to write helpers this way.

@Html.LabelFor(x=>m.SomeProperty) // here @ is telling that we are writing c# statement

the right way is to tell that this is a razor html helper and c# statement:

@if (SiteSession.SubPageHelper.DisplayType == DisplayType.List)
{
    @Html.Partial("_SubLandingPage_List")
}
else
{
    @Html.Partial("_SubLandingPage_Grid")
}

An alternative can be to use RenderPartial which will work in the if statement without putting @ sign:

@if (SiteSession.SubPageHelper.DisplayType == DisplayType.List)
    {
        Html.RenderPartial("_SubLandingPage_List");
    }
    else
    {
        Html.RenderPartial("_SubLandingPage_Grid");
    }
Html.Partial
Html.RenderPartial

But if it is considered plain text then why isn't that rendered to the screen instead of nothing at all. Also when I debugged and stepped through the code it still went into the partial but just didn't have anything in the products collection

razor syntax is to put @ and semicolon is not needed at end of its statement, you should read about razor syntax to get your mind clear how to use it

Ah okay, you were almost correct - it is still considered as c# instead of plain text as it is within the if statement being such you need to use HTML.RenderPartial("_SubLandingPage_List");. by putting the @ in front in makes it come back to Razor in which case the HTML.Partial is enough to render it. If you change your answer to reflect this I will accept it

Html.Partial does not return you the partial view in main view??

asp.net mvc 4 - Html.Partial not rendering partial view - Stack Overfl...

asp.net-mvc-4 razor asp.net-mvc-partialview
Rectangle 27 22

You can use Html.Raw(mystring). In myString you can write whatever you want, for example a tag opening or closing, without getting any errors at all. I.e.

if (condition) {
  @Html.Raw("<div>")
}

if (condition) {
  @Html.Raw("</div>")
}

NOTE: the @Html.Raw("<div>") can be written in a shorter, alternative form, like this: @:<div>

You can also create your own html helpers for simplifying the razor syntax. These helpers could receive the condition parameter, so that you can do something like this:

@Html.DivOpen(condition)

@Html.DivClose(condition)

Nor the Raw, neither the html helpers will be detected as "tags" so you can use them freely.

It would be much safer to implement something like the BeginForm html helper. You can look at the source code. It's easy to implement: you simply have to write the opening tag in the constructor, and the closing tag in the Dispose method. The adavantage of this technique is that you will not forget to close a conditionally opened tag.

You need to implement this html helper (an extension method declared in a static class):

public static ConditionalDiv BeginConditionalDiv(this HtmlHelper html, 
    bool condition)
  {
      ConditionalDiv cd = new ConditionalDiv(html, condition);
      if (condition) { cd.WriteStart(); }
      return cd; // The disposing will conditionally call the WriteEnd()
  }

Which uses a class like this:

public class ConditionalDiv : IDisposable
  {
      private HtmlHelper Html;
      private bool _disposed;
      private TagBuilder Div;
      private bool Condition;

      public ConditionalDiv(HtmlHelper html, bool condition)
      {
          Html = html;
          Condition = condition;
          Div = new TagBuilder("div");
      }

      public void Dispose()
      {
          Dispose(true /* disposing */);
          GC.SuppressFinalize(this);
      }

      protected virtual void Dispose(bool disposing)
      {
        if (!_disposed)
        {
            _disposed = true;
            if (Condition) { WriteEnd(); }
        }
      }

       public void WriteStart()
       {
           Html.ViewContext.Writer.Write(Div.ToString(TagRenderMode.StartTag));
       }

       private void WriteEnd()
       {
           Html.ViewContext.Writer.Write(Div.ToString(TagRenderMode.EndTag));
       }
  }

You can use this with the same pattern as BeginForm. (Disclaimer: this code is not fully tested, but gives an idea of how it works. You can accept extra parameters for attributes, tag names and so on).

Thanks - the question is really to see what strategies for this people are using out in the wild.

Woah. That's a pretty admirable answer.

Thanks. Helped me and I think @:<div> is better because it don't need to change " to ' or somethings other if HTML was complex. see stackoverflow.com/questions/11969070/

asp.net mvc - Razor syntax - how to conditionally wrap some inner HTML...

html asp.net-mvc razor
Rectangle 27 1

Tag Helpers are a new feature in MVC that you can use for generating HTML. The syntax looks same like as HTML but its processed by Razor on the server. Tag Helpers are in many ways an alternative syntax to Html Helper methods but they also provide some functionality that was either difficult or impossible to do with helper methods.

What is the correct Tag usage in ASP.net Core? TagHelpers vs HTML Help...

asp.net asp.net-mvc asp.net-core-mvc asp.net-core-1.0
Rectangle 27 7

Contrary to the responses you received for your other question Razor does not require that you return an HtmlString. The problem with your code right now is that you are writing directly to the response stream. Razor executes things inside-out which means that you can mess up the response order (see a similar question).

So in your case you could probably do this (though i haven't tested it):

public static void Theseus(this HtmlHelper html)
{
    var writer = new HtmlTextWriter(html.ViewContext.Writer);
    ...
}

Html Helpers are perfectly capable of either returning a HtmlString directly or void and writing to the context writer. For example, both Html.Partial and Html.RenderPartial work fine in Razor. I think what you are confusing is the syntax required to call one version and not the other.

<%: Html.Partial("Name") %>
<% Html.RenderPartial("Name") %>

You call each method differently. If you flip things around, things will just not work. Similarly in Razor:

@Html.Partial("Name")
@{ Html.RenderPartial("Name"); }

Now it just so happens that the syntax to use a void helper is a lot more verbose in Razor compared to Aspx. However, both work just fine. Unless you meant something else by "the issue is with a html helper not being able to return void".

By the way, if you really want to call your helper using this syntax: @Html.Theseus() you could do this:

public static IHtmlString Theseus(this HtmlHelper html)
{
    var writer = new HtmlTextWriter(html.ViewContext.Writer);
    ...
    return new HtmlString("");
}

But that's a bit of a hack.

I like the idea of instantiating the htmltextwriter using html.ViewContext.Writer. That sounds very precise and enlightens me, so voted you up. There is no reason NOT to use the ViewContext's writer, and it will eliminate the problems highligted in that other post.

However, the issue with a html helper not being able to return void, which is what this post is about, is not solved by your answer.

asp.net mvc - Adapting a Custom Html Helper for Razor (it uses HtmlTex...

asp.net-mvc html-helper razor
Rectangle 27 7

Contrary to the responses you received for your other question Razor does not require that you return an HtmlString. The problem with your code right now is that you are writing directly to the response stream. Razor executes things inside-out which means that you can mess up the response order (see a similar question).

So in your case you could probably do this (though i haven't tested it):

public static void Theseus(this HtmlHelper html)
{
    var writer = new HtmlTextWriter(html.ViewContext.Writer);
    ...
}

Html Helpers are perfectly capable of either returning a HtmlString directly or void and writing to the context writer. For example, both Html.Partial and Html.RenderPartial work fine in Razor. I think what you are confusing is the syntax required to call one version and not the other.

<%: Html.Partial("Name") %>
<% Html.RenderPartial("Name") %>

You call each method differently. If you flip things around, things will just not work. Similarly in Razor:

@Html.Partial("Name")
@{ Html.RenderPartial("Name"); }

Now it just so happens that the syntax to use a void helper is a lot more verbose in Razor compared to Aspx. However, both work just fine. Unless you meant something else by "the issue is with a html helper not being able to return void".

By the way, if you really want to call your helper using this syntax: @Html.Theseus() you could do this:

public static IHtmlString Theseus(this HtmlHelper html)
{
    var writer = new HtmlTextWriter(html.ViewContext.Writer);
    ...
    return new HtmlString("");
}

But that's a bit of a hack.

I like the idea of instantiating the htmltextwriter using html.ViewContext.Writer. That sounds very precise and enlightens me, so voted you up. There is no reason NOT to use the ViewContext's writer, and it will eliminate the problems highligted in that other post.

However, the issue with a html helper not being able to return void, which is what this post is about, is not solved by your answer.

asp.net mvc - Adapting a Custom Html Helper for Razor (it uses HtmlTex...

asp.net-mvc html-helper razor
Rectangle 27 8

If MVC Razor DropDownList HTML helper/wrapper syntax is applied, then you can use method HtmlAttributes to specify the width of dropdown list like:

@(Html.Kendo().DropDownList()                                                            .Name("myDDL")
.HtmlAttributes(new { style="width:100px" })

Kendo dropdown width - Stack Overflow

kendo-ui kendo-asp.net-mvc
Rectangle 27 3

@helper TextField(Employee employee, HtmlHelper<IEnumerable<Employee>> html)
{
    @html.TextBoxFor(x => employee.LastName)
}

<div id="grid1">
    @grid.GetHtml(columns: grid.Columns(
        grid.Column("LastName"),
        grid.Column(format: item => TextField(item.Value, Html))
    ))
</div>

Maybe there's a better approach though. Still learning the Razor syntax and quite frankly I am a bit disappointed by the WebGrid helper after having used MVCContrib Grid.

There most be a easier way a doing it.

@user408698, I hope there is but I am a bit skeptical.

Using this approach, when that form with textboxes is submitted back to a HttpPost action, how do you know which value belongs to which record?

@Boris B, you could include an additional hidden input containing the record id.

hidden id="RowId{N}" <=> textbox id="LastName{N}", N=1..RowCount

asp.net mvc - Mvc 3 texbox in webgrid (razor) - Stack Overflow

asp.net-mvc razor webgrid
Rectangle 27 1

I haven't found any way to move the "embedded HTML" into a partial view exactly, but a slightly more-friendly way to encapsulate the HTML in a way that provides HTML and Razor syntax highlighting and Intellisense is to move into a view helper function in a file under the app App_Code folder as described in this post on "Hugo Bonacci's Blog".

@helper HelpTextMessage(bool isHidden, string heading, Func<object, object> content)
{
    <div class="help-text @(isHidden ? "help-text-hidden" : "")">
        <div class="help-text-heading">
            @heading
        </div>
        <div class="help-text-body">
            @content(null)
        </div>
    </div>
}

Assuming the above helper function is in a file named ViewHelpers.cshtml in the App_Code folder, it can be called in a view like this:

@ViewHelpers.HelpTextMessage(false, "Something",
    <p>To do something, first do something-more-specific, then do another-something-more-specific.</p>
    <p>Also, keep in mind that you might need to do something-else-entirely if blah-blah-blah.</p>
)

I like having the embedded HTML in a view more than I do being able to use the @using(Html.HelpTextMessage(...){ ... } syntax, so I'm pretty happy with this as a solution.

razor - ASP.NET MVC3 HtmlHelper extension method like BeginForm that u...

asp.net-mvc-3 razor html-helper
Rectangle 27 1

I haven't found any way to move the "embedded HTML" into a partial view exactly, but a slightly more-friendly way to encapsulate the HTML in a way that provides HTML and Razor syntax highlighting and Intellisense is to move into a view helper function in a file under the app App_Code folder as described in this post on "Hugo Bonacci's Blog".

@helper HelpTextMessage(bool isHidden, string heading, Func<object, object> content)
{
    <div class="help-text @(isHidden ? "help-text-hidden" : "")">
        <div class="help-text-heading">
            @heading
        </div>
        <div class="help-text-body">
            @content(null)
        </div>
    </div>
}

Assuming the above helper function is in a file named ViewHelpers.cshtml in the App_Code folder, it can be called in a view like this:

@ViewHelpers.HelpTextMessage(false, "Something",
    <p>To do something, first do something-more-specific, then do another-something-more-specific.</p>
    <p>Also, keep in mind that you might need to do something-else-entirely if blah-blah-blah.</p>
)

I like having the embedded HTML in a view more than I do being able to use the @using(Html.HelpTextMessage(...){ ... } syntax, so I'm pretty happy with this as a solution.

razor - ASP.NET MVC3 HtmlHelper extension method like BeginForm that u...

asp.net-mvc-3 razor html-helper
Rectangle 27 3

It's difficult to help you with your current solution without seeing the code for your HtmlHelpers. However, an alternative (and quite common) approach would be to use Razor sections instead.

In your layout page define a section placholder using @RenderSection()

<head>
  <title>Page Title</title>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript"></script>
  @RenderSection("Scripts", required: false)
</head>

Then in your view define your section content

@section Scripts {
  <script src="myscript.js" type="text/javascript"></script>
}

If you want to save yourself some typing and make it even cleaner, you could create a HtmlHelper to output your script tag

public static MVcHtmlString AddScript(this HtmlHelper helper, string path) {
  //create script element html here
}

and then you can us a similar syntax style to your example

@section Scripts {
  @Html.AddScript("myscript.js")
}

I've just seen your edit. Note that this wouldn't prevent duplicate script declarations from being added

asp.net mvc - Moving MVC2 Helpers to MVC3 razor view engine - Stack Ov...

asp.net-mvc asp.net-mvc-3 html-helper razor
Rectangle 27 8

@{ Html.BeginForm(...); }
<div> content</div>
@{ Html.EndForm(); }

Unfortunately the Razor syntax right now is a bit more verbose when invoking helpers that write to the output (as opposed to the majority of helpers which just return an html snippet). You could probably make this easier by writing your own extension methods like so:

public static IHtmlString FormBegin(this HtmlHelper helper, ...) {
    helper.BeginForm(...);
    return new HtmlString("");
}

public static IHtmlString FormEnd(this HtmlHelper helper) {
    helper.EndForm();
    return new HtmlString("");
}

Thanks, this helped a lot!

In case anyone is still wondering why unobtrusive validation works only when using the Html.BeginForm magic, the answer is here stackoverflow.com/a/3501759

asp.net mvc 3 - Rewriting Html.BeginForm() in MVC 3.0 and keeping unob...

asp.net-mvc-3 html-helper unobtrusive-javascript html.beginform
Rectangle 27 8

@{ Html.BeginForm(...); }
<div> content</div>
@{ Html.EndForm(); }

Unfortunately the Razor syntax right now is a bit more verbose when invoking helpers that write to the output (as opposed to the majority of helpers which just return an html snippet). You could probably make this easier by writing your own extension methods like so:

public static IHtmlString FormBegin(this HtmlHelper helper, ...) {
    helper.BeginForm(...);
    return new HtmlString("");
}

public static IHtmlString FormEnd(this HtmlHelper helper) {
    helper.EndForm();
    return new HtmlString("");
}

Thanks, this helped a lot!

In case anyone is still wondering why unobtrusive validation works only when using the Html.BeginForm magic, the answer is here stackoverflow.com/a/3501759

asp.net mvc 3 - Rewriting Html.BeginForm() in MVC 3.0 and keeping unob...

asp.net-mvc-3 html-helper unobtrusive-javascript html.beginform
Rectangle 27 1

I suggest you move all this logic into a separate Section as it is a Menu that is being rendered.

Instead of building the HTML from the code, it is cleaner and a lot more convenient to build it using Razor's helpers. Refer to this as well as this article from Scott Gu on how to render sections to get a quick starting guide.

Consider using Helper methods such as

@Html.DropDownListFor()
@Html.DropDownList()

asp.net mvc - How to build html using HTML helpers in MVC3 - Stack Ove...

html asp.net-mvc asp.net-mvc-3 html-helper
Rectangle 27 0

I haven't found any way to move the "embedded HTML" into a partial view exactly, but a slightly more-friendly way to encapsulate the HTML in a way that provides HTML and Razor syntax highlighting and Intellisense is to move into a view helper function in a file under the app App_Code folder as described in this post on "Hugo Bonacci's Blog".

@helper HelpTextMessage(bool isHidden, string heading, Func<object, object> content)
{
    <div class="help-text @(isHidden ? "help-text-hidden" : "")">
        <div class="help-text-heading">
            @heading
        </div>
        <div class="help-text-body">
            @content(null)
        </div>
    </div>
}

Assuming the above helper function is in a file named ViewHelpers.cshtml in the App_Code folder, it can be called in a view like this:

@ViewHelpers.HelpTextMessage(false, "Something",
    <p>To do something, first do something-more-specific, then do another-something-more-specific.</p>
    <p>Also, keep in mind that you might need to do something-else-entirely if blah-blah-blah.</p>
)

I like having the embedded HTML in a view more than I do being able to use the @using(Html.HelpTextMessage(...){ ... } syntax, so I'm pretty happy with this as a solution.

razor - ASP.NET MVC3 HtmlHelper extension method like BeginForm that u...

asp.net-mvc-3 razor html-helper
Rectangle 27 0

Since you seem to be relatively new to ASP.NET MVC, and are making use of razor syntax, I'd suggest you to take advantage of the razor's syntax to achieve what you are looking for. There is an html helper provided by razor for displaying just that:labels. Here's the way you'd use it:

<div class=" col-md-12" style="margin: 0 auto;">
@Html.LabelFor(model => model.IsFemale, "Female")
@Html.RadioButtonFor(model => model.IsFemale,"false", new { htmlAttributes = new { @class = "form-control" } })
@Html.LabelFor(model => model.IsFemale, "Male")
@Html.RadioButtonFor(model => model.IsFemale, "true", new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.IsFemale, "", new { @class = "text-danger" })
</div>

html - Display radiobuttons and labels in a row - Stack Overflow

html css asp.net-mvc razor
Rectangle 27 0

After a dialogue with Telerik support the answer became evident. The @() syntax I was using doesn't work in vb.net and instead @Code....End Code should be used combined with a sub() @<text> .... </text> End Sub to encapsulate the HTML:

@code
    Html.Kendo().TabStrip() _
    .Name("tab2") _
    .Items(Function(tabstrip) tabstrip.Add().Text("Project") _
    .Selected(True).Content(Sub()@<text>
        <table id="SummaryDimPanel" class="table slim">
              ....table contents...
        </table>
    </text> End Sub)).Render()
End code

(This particular Kendo helper requires the addition of the .Render method to actually push the HTML to the browser).

asp.net mvc - Razor syntax in helper containing HTML - Stack Overflow

asp.net-mvc vb.net razor kendo-ui