this is my modal body .. it's a form to create a new product that should write a name and associate it to a catogory
@model mySolution.Models.
@using (Html.BeginForm("Product_Add", "", FormMethod.Post))
{
@Html.AntiForgeryToken()
<div class="form-horizontal" id="newProduct">
<div id="validation-summary">
</div>
<div class="form-group">
<div class="form-row">
@Html.LabelFor(model => model.ProductName, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.ProductName, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.ProductName, "", new { @class = "text-danger" })
</div>
</div>
</div>
<div class="form-group">
<div class="form-row">
@Html.LabelFor(model => model.ProductCategory, htmlAttributes: new { @class = "control-label col-md-2" })
@(Html.Kendo().DropDownList()
.Name("categoriesDropDownList")
.DataTextField("CategoryName")
.DataValueField("CategoryID")
.DataSource(source =>
{
source.Custom()
.ServerFiltering(true)
.Type("aspnetmvc-ajax")
.Transport(transport =>
{
transport.Read("Category_Read", "Category");
})
.Schema(schema =>
{
schema.Data("Data")
.Total("Total");
});
})
)
</div>
</div>
</div>
<br />
<div class="form-group">
<div class="form-row">
<div class="col-md-12" style="text-align: right;">
<input type="submit" value="Enregister" class="mr-1 mb-1 btn btn-primary" />
@Html.ActionLink("Annuler", "ProductList", "Products", null, new { @class = "mr-1 mb-1 btn btn-secondary" })
</div>
</div>
</div>
}
Product and Category are two differents table..I get the list of categories but when i want to submit the save of a new product ..i didn't get the correct value of categoryID and after submit :in the table of Product..it take the correct Name of Product filled and 0 as value of CategoryID
in the controller side i have an action method Product_Add(ProductModel model) that call a service to execute the save..
how can I get the correct CategoryID selected , pass it (Category_CategoryID_PK = Product_CategoryID_FK) and save it ? any propositions?
Thanks!