seahood
seahood
CC#
Created by Messiah on 1/13/2023 in #help
❔ Razor pages view
no probs! good luck!
22 replies
CC#
Created by Messiah on 1/13/2023 in #help
❔ Razor pages view
no problem! this article might be some good further reading https://www.learnrazorpages.com/razor-pages/model-binding
22 replies
CC#
Created by Messiah on 1/13/2023 in #help
❔ Razor pages view
yep, and i believe that the [BindProperty] attributes is for allowing the view to set values in the model, rather than just having them as "read only" in the view (not 100% on that though)
22 replies
CC#
Created by Messiah on 1/13/2023 in #help
❔ Razor pages view
no matter what the name of the model behind is in @model somerandommodelname, it will always be referred to after that point as Model in the view
22 replies
CC#
Created by Messiah on 1/13/2023 in #help
❔ Razor pages view
can you share the model class if possible?
22 replies
CC#
Created by Messiah on 1/13/2023 in #help
❔ Razor pages view
so in your snippet, in the model behind, there'll be some List<string> CompanyCafes, and the view can then access that by using Model.CompanyCafes
22 replies
CC#
Created by Messiah on 1/13/2023 in #help
❔ Razor pages view
i believe the ViewData is slightly different, that's something that's just automatically available without having to specify the model (i think)
22 replies
CC#
Created by Messiah on 1/13/2023 in #help
❔ Razor pages view
so if you create a new razor page in visual studio, there will be a SomePage.cshtml and an associated SomePage.cshtml.cs (you might need to expand the cshtml one to see it, like you would a folder). the .cs file is the model for the razor page
22 replies
CC#
Created by Messiah on 1/13/2023 in #help
❔ Razor pages view
in the razor code, Model refers to whatever class was used in the @model at the top
22 replies
CC#
Created by Messiah on 1/13/2023 in #help
❔ Razor pages view
at the top of the razor page code, there should be some @ entries, one of those should be @model SomeModel, which refers to a class to be used as the model
22 replies
CC#
Created by bisounours_ on 1/8/2023 in #help
❔ Image For inventory
Or you have one GameObject, and you want to take the image displayed on that and make that the image of the inventory GameObject?
7 replies
CC#
Created by bisounours_ on 1/8/2023 in #help
❔ Image For inventory
Are you trying to figure out how to set images on gameobjects at runtime, or how to instantiate a prefab at runtime?
7 replies
CC#
Created by seahood on 8/25/2022 in #help
Mapping outgoing enums to a specific shape in Asp.net Core [Answered]
i think i've resolved it by convincing it to use AddNewtonsoftJson() and using the converter we originally had
8 replies
CC#
Created by seahood on 8/25/2022 in #help
Mapping outgoing enums to a specific shape in Asp.net Core [Answered]
it's a huge legacy project with thousands of things depending on enums being the correct type in the DTOs, would take forever to change everything
8 replies
CC#
Created by seahood on 8/25/2022 in #help
Mapping outgoing enums to a specific shape in Asp.net Core [Answered]
This is as far as I got with the JsonConverter implementation that almost works:
public class ApiEnumConverter : JsonConverter<Enum>
{
public override Enum Read(
ref Utf8JsonReader reader,
Type objectType,
JsonSerializerOptions options)
{
var type = JsonSerializer.Deserialize<Enumeration>(reader.GetString());
var underlyingType = objectType.IsNullable()
? Nullable.GetUnderlyingType(objectType)
: objectType;
return (Enum)Enum.Parse(underlyingType, type.Id.ToString(CultureInfo.InvariantCulture));
}

public override void Write(
Utf8JsonWriter writer,
Enum value,
JsonSerializerOptions options) =>
JsonSerializer.Serialize(writer, EnumerationMapper.Map(value));


public override bool CanConvert(Type objectType)
{
if (objectType.IsEnum)
return true;

var nullableEnumType = Nullable.GetUnderlyingType(objectType);
return nullableEnumType != null && nullableEnumType.IsEnum;
}
}
public class ApiEnumConverter : JsonConverter<Enum>
{
public override Enum Read(
ref Utf8JsonReader reader,
Type objectType,
JsonSerializerOptions options)
{
var type = JsonSerializer.Deserialize<Enumeration>(reader.GetString());
var underlyingType = objectType.IsNullable()
? Nullable.GetUnderlyingType(objectType)
: objectType;
return (Enum)Enum.Parse(underlyingType, type.Id.ToString(CultureInfo.InvariantCulture));
}

public override void Write(
Utf8JsonWriter writer,
Enum value,
JsonSerializerOptions options) =>
JsonSerializer.Serialize(writer, EnumerationMapper.Map(value));


public override bool CanConvert(Type objectType)
{
if (objectType.IsEnum)
return true;

var nullableEnumType = Nullable.GetUnderlyingType(objectType);
return nullableEnumType != null && nullableEnumType.IsEnum;
}
}
8 replies