init
This commit is contained in:
commit
e124a47765
19374 changed files with 9806149 additions and 0 deletions
25
KretaWeb/Helpers/RequiredIfReflector.cs
Normal file
25
KretaWeb/Helpers/RequiredIfReflector.cs
Normal file
|
@ -0,0 +1,25 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace Kreta.Web.Helpers
|
||||
{
|
||||
public static class RequiredIfReflector
|
||||
{
|
||||
public static bool RequiredIf<TModel>(HtmlHelper<TModel> helper, IDictionary<string, object> validationAttributes)
|
||||
{
|
||||
if (validationAttributes.Keys.Contains("data-val-requiredif-dependentproperty") && validationAttributes.Keys.Contains("data-val-requiredif-dependentvalue"))
|
||||
{
|
||||
string dependentPropertyName = (string)validationAttributes["data-val-requiredif-dependentproperty"];
|
||||
|
||||
object requiredValue = validationAttributes["data-val-requiredif-dependentvalue"];
|
||||
|
||||
var propertyInfo = helper.ViewData.Model.GetType().GetProperty(dependentPropertyName);
|
||||
|
||||
object dependentPropertyValue = propertyInfo.GetValue(helper.ViewData.Model);
|
||||
|
||||
return requiredValue.Equals(dependentPropertyValue);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue