c# - Passing data from one form to another in asp.net mvc -
i want pass data 1 form another. have form of products , after submitting form want add buttom add posts product, want pass product id other form.
this product.cs:
public partial class produits { public produits() { this.postes = new hashset<postes>(); } public int idproduit { get; set; } public int idpole { get; set; } public nullable<int> reference { get; set; } public string designationproduit { get; set; } public virtual pole pole { get; set; } public virtual icollection<postes> postes { get; set; } }
this post.cs:
public partial class postes { public int idposte { get; set; } public nullable<int> numero { get; set; } public int idproduit { get; set; } public int idatelier { get; set; } public string designationposte { get; set; } public virtual atelier atelier { get; set; } public virtual produits produits { get; set; } }
this create.cshtml product:
@using (html.beginform()) { @html.antiforgerytoken() <div class="form-horizontal"> <h4>produits</h4> <hr /> @html.validationsummary(true, "", new { @class = "text-danger" }) <div class="form-group"> @html.labelfor(model => model.idpole, "pole", htmlattributes: new { @class = "control-label col-md-2" }) <div class="col-md-10"> @html.dropdownlist("idpole", null, htmlattributes: new { @class = "form-control" }) @html.validationmessagefor(model => model.idpole, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @html.labelfor(model => model.reference, htmlattributes: new { @class = "control-label col-md-2" }) <div class="col-md-10"> @html.editorfor(model => model.reference, new { htmlattributes = new { @class = "form-control" } }) @html.validationmessagefor(model => model.reference, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @html.labelfor(model => model.designationproduit, htmlattributes: new {@class = "control-label col-md-2"}) <div class="col-md-10"> @html.editorfor(model => model.designationproduit, new {htmlattributes = new {@class = "form-control"}}) @html.validationmessagefor(model => model.designationproduit, "", new {@class = "text-danger"}) </div> </div> <div class="form-group"> <div class="col-md-offset-2 col-md-10"> <input type="submit" value="create" class="btn btn-default" /> </div> </div> </div> }
and create.cshtml post:
<form asp-controller="postes" asp-action="create" method="post" id="formps" role="form"> @html.antiforgerytoken() <div class="form-horizontal"> <h4>postes</h4> <hr /> @html.validationsummary(true, "", new { @class = "text-danger" }) <div class="form-group"> @html.labelfor(model => model.idproduit, "produit", htmlattributes: new {@class = "control-label col-md-2"}) <div class="col-md-10"> @html.dropdownlist("idproduit", null, htmlattributes: new {@class = "form-control"}) @html.validationmessagefor(model => model.idatelier, "", new {@class = "text-danger"}) </div> </div> <div class="form-group"> @html.labelfor(model => model.idatelier, "atelier", htmlattributes: new { @class = "control-label col-md-2" }) <div class="col-md-10"> @html.dropdownlist("idatelier", null, htmlattributes: new { @class = "form-control" }) @html.validationmessagefor(model => model.idatelier, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @html.labelfor(model => model.designationposte, htmlattributes: new { @class = "control-label col-md-2" }) <div class="col-md-10"> @html.editorfor(model => model.designationposte, new { htmlattributes = new { @class = "form-control" } }) @html.validationmessagefor(model => model.designationposte, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> <div class="col-md-offset-2 col-md-10"> <input type="submit" value="create" class="btn btn-default" /> </div> </div> </div> }
my product controller:
public actionresult create([bind(include = "idproduit,idpole,reference,designationproduit")] produits produits) { if (modelstate.isvalid) { db.produits.add(produits); db.savechanges(); return redirecttoaction("index"); } viewbag.idpole = new selectlist(db.pole, "id", "designation", produits.idpole); return view(produits); }
my post controller:
public actionresult create(postes postes) { if (modelstate.isvalid) { db.postes.add(postes); db.savechanges(); return redirecttoaction("index"); } viewbag.idatelier = new selectlist(db.atelier, "id", "designationatelier", postes.idatelier); viewbag.idproduit = new selectlist(db.produits, "idproduit", "designationproduit", postes.idproduit); return view(); }
i want pass idproduit other form, idproduit not manually added.
Comments
Post a Comment