About .NET, ASP.NET, MVC, C#, WPF, WCF and everything related to .NET and more.

Captcha Mvc [Split markup and script generation]

CaptchaMvc supports the ability to split scripts and markup. When call any extension method to create captcha it returns an object of type ICaptcha, here are the the interface:

/// <summary>
///     Represents the captcha model.
/// </summary>
public interface ICaptcha : IHtmlString
{
    /// <summary>
    ///     Gets the <see cref="IBuildInfoModel"/>.
    /// </summary>
    IBuildInfoModel BuildInfo { get; }

    /// <summary>
    ///     Renders only captcha markup, if any.
    /// </summary>
    /// <returns>
    ///     An instance of <see cref="IHtmlString" />.
    /// </returns>
    IHtmlString RenderMarkup();

    /// <summary>
    ///     Renders only captcha scripts, if any.
    /// </summary>
    /// <returns>
    ///     An instance of <see cref="IHtmlString" />.
    /// </returns>
    IHtmlString RenderScript();
}
Simple example of split markup and script generation:
@using CaptchaMvc.HtmlHelpers
@using CaptchaMvc.Interface
@{
    ViewBag.Title = "SplitMarkupAndScript";
    ICaptcha captcha = Html.MathCaptcha("Refresh", "Input", "Is required field.", true);
}
@section Scripts
{
    @captcha.RenderScript()
}

<h2>The captcha render with Html.MathCaptcha("Refresh", "Input", "Is required field.", true)</h2>
@using (Html.BeginForm())
{
    @captcha.RenderMarkup()
    <br />
    <input type="submit" value="Send"/>
}

Comments

This is exactly what I needed. Although I'm 100% sure this works in partial views yet. Still testing.

Thanks.

Leave a Reply
*bold*
_italics_
+underline+
* Bullet List
** Bullet List 2
# Number List
## Number List 2
{"Do not apply formatting"}
{code:language} code here {code:language}.
Supports: aspx c#, c#, c++, html, sql, xml
[url:http://www.example.com]