Hy i'm beginner in asp.net MVC and i have i issue!! my problem is i have 2 model log_ligne_voyage and log_ligne_demande_voyage my problem is i'm usion checkBox i want when i click on the button "Planifier" as shoing the image i want the value of the selected row of the table log_ligne_demande_voyage to add in the table log_ligne_voyage. Sorry for my englisch i don't speak very good english This is the image this is log_ligne_demande_voyage code :
public partial class log_ligne_demande_voyage
{
public log_ligne_demande_voyage()
{
this.log_ligne_voyage = new HashSet<log_ligne_voyage>();
}
public int ID_LIG { get; set; }
public Nullable<int> ID_TYPE_LIG { get; set; }
public Nullable<int> ID_ETAT_LIG { get; set; }
public Nullable<int> NUM_DEM { get; set; }
public Nullable<int> ID_PER { get; set; }
public string CMT_LIG { get; set; }
public Nullable<double> QTE_LIG { get; set; }
public Nullable<System.DateTime> CrtDateAuto { get; set; }
public string Lieu_Dem { get; set; }
public int Num_Dem { get; set; }
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public DateTime Date { get; set; }
[DisplayFormat(DataFormatString = "{0:hh\\:mm}", ApplyFormatInEditMode = true)]
public TimeSpan Heure { get; set; }
public Nullable<int> ID_file { get; set; }
this is log_ligne_voyage Model code :
public partial class log_ligne_voyage
{
public int ID_LIG_voy { get; set; }
public Nullable<int> ID_TYPE_LIG_voy { get; set; }
public Nullable<int> ID_ETAT_LIG_voy { get; set; }
public Nullable<int> NUM_Voy { get; set; }
public Nullable<int> ID_PER { get; set; }
public string CMT_LIG_voy { get; set; }
public Nullable<double> QTE_LIG_voy { get; set; }
public string Lieu_LIG_voy { get; set; }
public Nullable<int> ID_File { get; set; }
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public DateTime Date_LIG_voy { get; set; }
[DisplayFormat(DataFormatString = "{0:hh\\:mm}", ApplyFormatInEditMode = true)]
public TimeSpan Heure_LIG_voy { get; set; }
public Nullable<System.DateTime> CrtDateAuto { get; set; }
public Nullable<int> ID_Ligne { get; set; }
public virtual log_ligne_demande_voyage log_ligne_demande_voyage { get; set; }
public virtual log_voyage log_voyage { get; set; }
public virtual log_type_demande log_type_demande { get; set; }
public virtual log_personnel log_personnel { get; set; }
public virtual log_voyage_file log_voyage_file { get; set; }
public virtual log_voy_etat log_voy_etat { get; set; }
}
} this is the controller code :
[HttpPost]
public ActionResult LigneCheked(/*IEnumerable<log_ligne_demande_voyage> LigneVoyage*/ int[] selectedligne, log_ligne_demande_voyage item)
{
try
{
if (Session["login"] == null)
{
return RedirectToAction("Index", new { controller = "Login", action = "Index" });
}
login = Session["login"].ToString();
log_voyage model = new log_voyage();
model.UserCrt_Voy = login;
model.Dat_Voy = DateTime.Today;
entities.Set<log_voyage>().Add(model);
entities.SaveChanges();
//fine the bigest ID of the voyage
int MaxID = int.MaxValue;
foreach (DataRow db in log_voyage.Rows)
{
int ID_Voy = db.Field<int>("Num_Voy");
MaxID = Math.Max(MaxID, ID_Voy);
}
int intIdt = entities.log_voyage.Max(u => u.Num_Voy);
foreach (var item1 in selectedligne)
{
log_ligne_voyage model1 = new log_ligne_voyage();
item.ID_ETAT_LIG = 3;
model1.Date_LIG_voy = item.Date;
model1.CMT_LIG_voy = item.CMT_LIG;
model1.ID_Ligne = item.ID_LIG;
model1.ID_TYPE_LIG_voy = item.ID_TYPE_LIG;
model1.ID_PER = item.ID_PER;
model1.QTE_LIG_voy = item.QTE_LIG;
model1.Lieu_LIG_voy = item.Lieu_Dem;
model1.ID_File = item.ID_file;
model1.Heure_LIG_voy = item.Heure;
model1.ID_ETAT_LIG_voy = item.ID_ETAT_LIG;
model1.NUM_Voy = intIdt;
entities.Set<log_ligne_voyage>().Add(model1);
entities.SaveChanges();
return RedirectToAction("Index", "CreationVoyage");
}
}
catch (DataException /* dex */)
{
ModelState.AddModelError("", "Impossible d'executer cette action. contacter le service info SVP.");
return View("CreationVoyage");
}
return View("CreationVoyage");
}
}
this is the View Code :
@foreach(var item in Model)
{
<tr>
<td>
<input type="checkbox" id="checkAll" name="selectedligne" value="@item.ID_LIG" />
</td>
Aucun commentaire:
Enregistrer un commentaire