Making Model = IsRequired

May 19, 2013 at 2:31 PM
Edited May 19, 2013 at 2:32 PM
Hello, nice captcha, but I would like to ask you how could I make model as is required?

I'm using modified partial view this helper

Html.Captcha(int, string, string, ViewDataDictionary = null, params ParameterModel[])

In the PartialView, if you look at the code you see that there is a:
       @if (Model.IsRequired)
        {
            @Html.TextBox(Model.InputElementId, null, new Dictionary<string, object>
                {
                       {"data-val", "true"},
                        {"data-val-required", Model.RequiredMessage}
                 })
        }
        else
        {
            @Html.TextBox(Model.InputElementId)
        }
Which tests if model is required etc ... which is really cool and i need to be able to set it to true

How can i do this from this with this helper Html.Captcha(int, string, string, ViewDataDictionary = null, params ParameterModel[]) ???

Of course I could pass my own parameters and test on it, but i would like to set IsRequired to true ...

Is there a clear way to do that?

Thanks
Coordinator
May 19, 2013 at 4:24 PM
Hi there,
Yes you can, you just need to pass this parameter and the IsRequired property will be equal to true:
new ParameterModel(DefaultCaptchaManager.IsRequiredAttribute, true)
Regards,
Vyacheslav Volkov
May 19, 2013 at 5:05 PM
Ok, thanks mate :)

Good job on it btw on the Captcha, keep going and make it more developer friendly :)