Может кто-нибудь объяснить мне, почему это не работает?Я прочитал много сообщений о нескольких кнопках отправки на одной странице, но я не понимаю, что происходит в фоновом режиме.Я пытался следить за тем, что, как я вижу, делают другие в этих постах, но, похоже, ничего из этого не работает.Я просто пытаюсь понять, что на самом деле здесь происходит.Я подозреваю, что это как-то связано с тем, что именно происходит при публикации страницы.
Обе кнопки делают совершенно разные вещи. первая кнопка отправляет форму.В почтовом индексе формы он перенаправляется на Автомобиль / Индекс . вторая кнопка не публикует форму и переходит непосредственно к / Vehicle / CreateNewVehiclePart .
Вот что я хочу.Я хочу, чтобы обе кнопки отправили форму (чтобы я мог выполнить проверку и сохранить изменения в транспортном средстве, прежде чем двигаться дальше).После сохранения данных транспортного средства я хочу перейти к / Vehicle / AddPartsToVehicle или / Vehicle / CreateNewVehiclePart в зависимости от того, какая кнопка нажата.
<table class="layouttable">
<tr>
<td>
@using (Html.BeginForm("AddPartsToVehicle", "Vehicle", FormMethod.Post, null))
{
<input type="submit" value="Add Parts To Vehicle" />
}
</td>
<td>
@using (Html.BeginForm("CreateNewVehiclePart", "Vehicle", FormMethod.Post, null))
{
<input type="submit" value="Create New Vehicle Part" />
}
</td>
</tr>
</table>
Здесьэто модель транспортного средства:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
namespace ShopLog.Models
{
public class Vehicle
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid VehicleID { get; set; }
[Timestamp]
public Byte[] Timestamp { get; set; }
[Required]
[Display(Name = "Vehicle Name")]
[MaxLength(30, ErrorMessage = "The {0} must be no more than {2} characters long.")]
public string VehicleName { get; set; }
[Display(Name = "Assigned To")]
[MaxLength(30, ErrorMessage= "The {0} must be no more than {2} characters long.")]
public string AssignedTo { get; set; }
[Display(Name = "ID Number")]
[MaxLength(30, ErrorMessage = "The {0} must be no more than {2} characters long.")]
public string IDNumber { get; set; }
[Display(Name = "Active")]
public bool Active { get; set; }
[Display(Name = "Sign Out Vehicle")]
public bool SignOutVehicle { get; set; }
[Display(Name = "Have Title")]
public bool HaveTitle { get; set; }
[Display(Name = "Mileage or Hours")]
public int? MileageOrHours { get; set; }
[Display(Name = "Make")]
[MaxLength(30, ErrorMessage = "The {0} must be no more than {2} characters long.")]
public string Make { get; set; }
[Display(Name = "Model")]
[MaxLength(30, ErrorMessage = "The {0} must be no more than {2} characters long.")]
public string Model { get; set; }
[Display(Name = "Year")]
public int? Year { get; set; }
[Display(Name = "Engine")]
[MaxLength(30, ErrorMessage = "The {0} must be no more than {2} characters long.")]
public string Engine { get; set; }
[Display(Name = "Transmission Gears")]
public int? TransmissionGears { get; set; }
[Display(Name = "VIN")]
[MaxLength(30, ErrorMessage = "The {0} must be no more than {2} characters long.")]
public string VIN { get; set; }
[Display(Name = "Serial Number")]
[MaxLength(30, ErrorMessage = "The {0} must be no more than {2} characters long.")]
public string SerialNumber { get; set; }
[Display(Name = "Color")]
[MaxLength(30, ErrorMessage = "The {0} must be no more than {2} characters long.")]
public string Color { get; set; }
[Display(Name = "Air Filter")]
[MaxLength(30, ErrorMessage = "The {0} must be no more than {2} characters long.")]
public string AirFilter { get; set; }
[Display(Name = "Engine Oil Filter")]
[MaxLength(30, ErrorMessage = "The {0} must be no more than {2} characters long.")]
public string EngineOilFilter { get; set; }
[Display(Name = "Fuel Filter")]
[MaxLength(30, ErrorMessage = "The {0} must be no more than {2} characters long.")]
public string FuelFilter { get; set; }
[Display(Name = "Transmission Oil Filter")]
[MaxLength(30, ErrorMessage = "The {0} must be no more than {2} characters long.")]
public string TransmissionOilFilter { get; set; }
[Display(Name = "HydraulicOilFilter")]
[MaxLength(30, ErrorMessage = "The {0} must be no more than {2} characters long.")]
public string HydraulicOilFilter { get; set; }
[Display(Name = "Interior A/C Filter")]
[MaxLength(30, ErrorMessage = "The {0} must be no more than {2} characters long.")]
public string InteriorACFilter { get; set; }
[Display(Name = "Differential Oil")]
[MaxLength(30, ErrorMessage = "The {0} must be no more than {2} characters long.")]
public string DifferentialOil { get; set; }
[Display(Name = "Transmission Oil")]
[MaxLength(30, ErrorMessage = "The {0} must be no more than {2} characters long.")]
public string TransmissionOil { get; set; }
[Display(Name = "Engine Oil")]
[MaxLength(30, ErrorMessage = "The {0} must be no more than {2} characters long.")]
public string EngineOil { get; set; }
[Display(Name = "Tire Size")]
[MaxLength(30, ErrorMessage = "The {0} must be no more than {2} characters long.")]
public string TireSize { get; set; }
[Display(Name = "Tire Pressure")]
[MaxLength(30, ErrorMessage = "The {0} must be no more than {2} characters long.")]
public string TirePressure { get; set; }
[Display(Name = "Smog Due Date")]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:d}")]
public DateTime? SmogDue { get; set; }
[Display(Name = "Registration Due Date")]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:d}")]
public DateTime? RegistrationDue { get; set; }
[Display(Name = "Insurance Due Date")]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:d}")]
public DateTime? InsuranceDue { get; set; }
[Display(Name = "License Plate")]
[MaxLength(30, ErrorMessage = "The {0} must be no more than {2} characters long.")]
public string LicensePlate { get; set; }
[Display(Name = "Owner")]
[MaxLength(30, ErrorMessage = "The {0} must be no more than {2} characters long.")]
public string Owner { get; set; }
[Display(Name = "Previous Owner")]
[MaxLength(30, ErrorMessage = "The {0} must be no more than {2} characters long.")]
public string PreviousOwner { get; set; }
[Display(Name = "Date Acquired")]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:d}")]
public DateTime? DateAcquired { get; set; }
[Display(Name = "Notes")]
[DataType(DataType.MultilineText)]
public string Notes { get; set; }
[Required(ErrorMessage="Vehicle Type is required.")]
public Guid VehicleTypeID { get; set; }
public Guid? TransmissionTypeID { get; set; }
//A vehicle can only have one VehicleType and one TransmissionType
[Display(Name = "Vehicle Type")]
public virtual VehicleType VehicleType { get; set; }
[Display(Name = "Transmission Type")]
public virtual TransmissionType TransmissionType { get; set; }
//A vehicle can have many Parts
[Display(Name = "Parts")]
public virtual ICollection<Part> Parts { get; set; }
//A vehicle can have many Warranties
[Display(Name = "Warranties")]
public virtual ICollection<Warranty> Warranties {get; set; }
}
}
Вот модель части:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
namespace ShopLog.Models
{
public class Part
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid PartID { get; set; }
public string Name { get; set; }
public decimal Cost { get; set; }
[DataType(DataType.MultilineText)]
public string Notes { get; set; }
//A Part can belong to many Vehicles
public virtual ICollection<Vehicle> Vehicles { get; set; }
}
}