Fontos kezelési javítások
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
using Microsoft.AspNetCore.Mvc.ViewFeatures;
|
||||
using Microsoft.AspNetCore.Razor.TagHelpers;
|
||||
|
||||
namespace WorkFlowCheck.Web.Helpers
|
||||
{
|
||||
[HtmlTargetElement("input", Attributes = "asp-for-datatype")]
|
||||
public class AspForDataTypeTagHelper : TagHelper
|
||||
{
|
||||
[HtmlAttributeName("asp-for-datatype")]
|
||||
public ModelExpression For { get; set; }
|
||||
|
||||
public override void Process(TagHelperContext context, TagHelperOutput output)
|
||||
{
|
||||
if (For == null) return;
|
||||
|
||||
var type = For.ModelExplorer.ModelType;
|
||||
|
||||
string dataType = GetDataTypeString(type);
|
||||
output.Attributes.SetAttribute("data-type", dataType);
|
||||
}
|
||||
|
||||
private string GetDataTypeString(Type type)
|
||||
{
|
||||
// Nullable<T> esetén nyerjük ki az alaptípust
|
||||
if (Nullable.GetUnderlyingType(type) is Type underlyingType)
|
||||
{
|
||||
type = underlyingType;
|
||||
}
|
||||
|
||||
if (type == typeof(string)) return "string";
|
||||
if (type == typeof(int) || type == typeof(long) || type == typeof(float) ||
|
||||
type == typeof(double) || type == typeof(decimal)) return "number";
|
||||
if (type == typeof(bool)) return "bool";
|
||||
if (type == typeof(DateTime)) return "date";
|
||||
|
||||
return "string"; // default fallback
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user