public class BikeModel
{
[Required]
public int UserID { get; set; }
public int BicycleID { get; set; }
[Required]
public string Brand { get; set; }
public List ListBrand { get; set; }
[Required]
public string Category { get; set; }
public List ListCategory { get; set; }
[Required]
public string Description { get; set; }
[Required]
public string Image { get; set; }
public BikeModel()
{
ListBrand = new List
{
new SelectListItem{Value="Electra",Text="Electra"},
new SelectListItem{Value="Haro",Text="Haro"},
new SelectListItem{Value="Heller", Text = "Heller"},
new SelectListItem{Value="Pure Cycles", Text = "Pure Cycles"},
new SelectListItem{Value="Ritchey", Text = "Ritchey"},
new SelectListItem{Value="Strider", Text = "Strider"},
new SelectListItem{Value="Sun Bicycles", Text = "Sun Bicycles"},
new SelectListItem{Value="Surly", Text = "Surly"},
new SelectListItem{Value="Trek", Text = "Trek"},
};
ListCategory = new List
{
new SelectListItem{Value="Children Bicycles", Text = "Children Bicycles"},
new SelectListItem{Value="Comfort Bicycles", Text = "Comfort Bicycles"},
new SelectListItem{Value="Cruisers Bicycles", Text = "Cruisers Bicycles"},
new SelectListItem{Value="Cyclocross Bicycles", Text = "Cyclocross Bicycles"},
new SelectListItem{Value="Electric Bikes", Text = "Electric Bikes"},
new SelectListItem{Value="Mountain Bikes", Text = "Mountain Bikes"},
new SelectListItem{Value="Road Bikes", Text = "Road Bikes"},
};
}
Я пробовал использовать множество вещей, включая метод get, но не могу отправить форму, и большинство решений относились к ASP.NET Core, а я работаю над .NET Framework. Я также попытался воссоздать проект и добавить обработку исключений в метод http-post.
Действие в BicycleController: [code] public ActionResult SellerAddPage() { var model = new BikeModel(); return View(model); }
[HttpPost] public ActionResult SellerAddPage(BikeModel bicycle, HttpPostedFileBase Image) { try { // Save image to folder if (Image != null && Image.ContentLength > 0) { var fileName = Path.GetFileName(Image.FileName); var path = Path.Combine(Server.MapPath("~/Content/Image"), fileName); Image.SaveAs(path); bicycle.Image = "/Content/Images/" + fileName; // Save the relative path in the database }
int? userId = Session["UserId"] as int?;
if (userId == null) { // Handle case where UserId is not in session (user not logged in or session expired) ViewBag.ErrorMessage = "User is not logged in."; return View(bicycle); } else { bicycle.UserID = userId.Value; // Save bicycle details to the database using (var connection = new SqlConnection(connectionString)) { string query = "INSERT INTO [sales].[bicycle] (user_id,brand_name, category_name, description, picture) VALUES (@user_id,@brand_name, @category_name, @description, @picture)";
return View("SellerPage"); } [/code] Модель [code]public class BikeModel { [Required] public int UserID { get; set; } public int BicycleID { get; set; } [Required] public string Brand { get; set; } public List ListBrand { get; set; } [Required] public string Category { get; set; } public List ListCategory { get; set; } [Required] public string Description { get; set; } [Required] public string Image { get; set; }
public BikeModel() { ListBrand = new List { new SelectListItem{Value="Electra",Text="Electra"}, new SelectListItem{Value="Haro",Text="Haro"}, new SelectListItem{Value="Heller", Text = "Heller"}, new SelectListItem{Value="Pure Cycles", Text = "Pure Cycles"}, new SelectListItem{Value="Ritchey", Text = "Ritchey"}, new SelectListItem{Value="Strider", Text = "Strider"}, new SelectListItem{Value="Sun Bicycles", Text = "Sun Bicycles"}, new SelectListItem{Value="Surly", Text = "Surly"}, new SelectListItem{Value="Trek", Text = "Trek"}, };
ListCategory = new List { new SelectListItem{Value="Children Bicycles", Text = "Children Bicycles"}, new SelectListItem{Value="Comfort Bicycles", Text = "Comfort Bicycles"}, new SelectListItem{Value="Cruisers Bicycles", Text = "Cruisers Bicycles"}, new SelectListItem{Value="Cyclocross Bicycles", Text = "Cyclocross Bicycles"}, new SelectListItem{Value="Electric Bikes", Text = "Electric Bikes"}, new SelectListItem{Value="Mountain Bikes", Text = "Mountain Bikes"}, new SelectListItem{Value="Road Bikes", Text = "Road Bikes"}, }; } [/code] Вот мое мнение: [code]@model u23704137_HW02.Models.BikeModel
} [/code] Я пробовал использовать множество вещей, включая метод get, но не могу отправить форму, и большинство решений относились к ASP.NET Core, а я работаю над .NET Framework. Я также попытался воссоздать проект и добавить обработку исключений в метод http-post.
Я пытаюсь войти в систему, это мой php-код, но ничего не возвращается, когда я нажимаю «Отправить», даже если я ввожу правильный пароль, поэтому пароль _verify не работает в моем браузере или я ввожу неверный код. Я потратил 3 дня, чтобы решить...