C
C#2w ago
Al3mid3x

✅ The value '(image path)' is not valid for Image.

Hey guys i'm new to Web development in general So basically i made an input for image file for a product in an ECommerce Project but whenever i press the save button i get The value 'value goes here' is not valid for Image here is a picture of what i'm facing:
No description
1 Reply
Al3mid3x
Al3mid3x2w ago
Product Class:
c#
using System.ComponentModel.DataAnnotations;

namespace Giftos.Entities
{
public class Product
{
[Key]
public Guid Id { get; set; }

[Required(ErrorMessage = "This field is required.")]
public string Name { get; set; }

[Required(ErrorMessage = "This field is required.")]
public string Description { get; set; }

[Required(ErrorMessage = "This field is required.")]
public int Stock { get; set; }

[Required(ErrorMessage = "This field is required.")]
public int Price { get; set; }

public byte[] Image { get; set; }




public Product(string name, string description, int price, int stock, byte[] image)
{
Name = name;
Description = description;
Price = price;
Stock = stock;
Image = image;
}

public Product() { }
}
}
c#
using System.ComponentModel.DataAnnotations;

namespace Giftos.Entities
{
public class Product
{
[Key]
public Guid Id { get; set; }

[Required(ErrorMessage = "This field is required.")]
public string Name { get; set; }

[Required(ErrorMessage = "This field is required.")]
public string Description { get; set; }

[Required(ErrorMessage = "This field is required.")]
public int Stock { get; set; }

[Required(ErrorMessage = "This field is required.")]
public int Price { get; set; }

public byte[] Image { get; set; }




public Product(string name, string description, int price, int stock, byte[] image)
{
Name = name;
Description = description;
Price = price;
Stock = stock;
Image = image;
}

public Product() { }
}
}
Input code:
<div class="col-md-4">
<div class="form-group">
<label asp-for="Image" class="w-100"></label>
@if (Model.Image != null)
{
<img id="img" alt="Product Image" src="data:image/*;base64,@(Convert.ToBase64String(Model.Image))"
style="height: 290px; width: 290px; object-fit: cover;" />
}
else
{
<img id="img" alt="Product Image" src="~/images/no-picture.jpg" style="height: 290px; width: 290px; object-fit: cover;" />
}
<div class="custom-file mt-2">
<input type="file" accept=".png" asp-for="Image" class="custom-file-input"/>
<label class="custom-file-label">Select A Photo...</label>
<span asp-validation-for="Image" class="text-danger"></span>
</div>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label asp-for="Image" class="w-100"></label>
@if (Model.Image != null)
{
<img id="img" alt="Product Image" src="data:image/*;base64,@(Convert.ToBase64String(Model.Image))"
style="height: 290px; width: 290px; object-fit: cover;" />
}
else
{
<img id="img" alt="Product Image" src="~/images/no-picture.jpg" style="height: 290px; width: 290px; object-fit: cover;" />
}
<div class="custom-file mt-2">
<input type="file" accept=".png" asp-for="Image" class="custom-file-input"/>
<label class="custom-file-label">Select A Photo...</label>
<span asp-validation-for="Image" class="text-danger"></span>
</div>
</div>
</div>
nvm i forgot to put enctype="multipart/form-data" in form element anyways there is some wierd error happining that when i select a photo the application exists and i got this message in output
The program '[24288] Giftos.exe' has exited with code 4294967295 (0xffffffff).

The program '[24288] Giftos.exe' has exited with code 4294967295 (0xffffffff).