Fontos kezelési javítások

This commit is contained in:
2025-06-04 12:25:04 +02:00
parent 6839fc0b78
commit ff9d6ae361
7 changed files with 66 additions and 9 deletions
@@ -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
}
}
}