I am working on an ASP.NET Core 5 MVC application, and i'm trying to display a bootstrap modal popup. I used the code below:
Index.cshtml:
<button type="button" class="btn btn-info" data-toggle="modal" data-target="#addEmp">
Ajouter
</button>
<table class="table table-bordered table-hover text-center">
...
</table>
_EmployeePartialView.cshtml:
#model Employee
<div class="modal fade" id="addEmp" aria-labelledby="addEmpLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="addEmpLabel">Employee</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form asp-action="Create">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="Name" class="control-label"></label>
<input asp-for="Name" class="form-control" />
<span asp-validation-for="Name" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Profession" class="control-label"></label>
<input asp-for="Profession" class="form-control" />
<span asp-validation-for="Profession" class="text-danger"></span>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
EmployeeController:
public IActionResult Index()
{
List<Employee> emp = _dbcontext.Employees.ToList();
return View(emp);
}
[HttpGet]
public IActionResult Create()
{
Employee emp = new Employee();
return PartialView("_EmployeePartialView", emp);
}
But when i click on the button the modal popup is not showing without any errors. any suggestions??
1.Please firstly check if the partial view correctly load to your html page. You can F12 and check the Elements panel in browser.
2.Then please check your bootstrap version,because if you use Bootstrap v 5.0, it used data-bs-target instead of data-target.
3.Be sure the partial view locates in Views/Shared/ or Views/Employee/ folder.
Not sure how do you render the partial view, below I share two ways to render the partial view.
Use html helper to display the partial view:
#model List<Employee>
<button type="button" class="btn btn-info" data-toggle="modal" data-target="#addEmp">
Ajouter
</button>
<table class="table table-bordered table-hover text-center">
//...
</table>
#await Html.PartialAsync("_EmployeePartialView", new Employee())
Use ajax to call Create action to display the partial view:
#model List<Employee>
<button type="button" class="btn btn-info" data-toggle="modal" data-target="#addEmp">
Ajouter
</button>
<table class="table table-bordered table-hover text-center">
</table>
<div id="display">
</div>
#section Scripts
{
<script>
$(function(){
$.ajax({
type: "get",
url: "/Employee/Create",
success: function (data) {
$("#display").html(data);
}
})
})
</script>
}
Result:
I work on one project for college and I have one problem...Does anyone know why I don't want to enter data into the database after adding by modal method. It is also not updated. And it doesn’t throw out a single mistake. Namely, I would like to have a crud operation on the same page, ie not to switch to another url when clicking on edit, add ... Just to add that the delete button is the only one of these three ...
index.blade.php
<?php
use App\Models\User;
use App\Models\Client;
use App\Models\Event;
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bootstrap CRUD Data Table for Database with Modal Form</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto|Varela+Round">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<body>
<div class="container">
<div class="table-wrapper">
<div class="table-title">
<div class="row">
<div class="col-sm-6">
<h2>Uredi <b>klijente</b></h2>
</div>
<div class="col-sm-6">
<i class="material-icons"></i> <span>Dodaj novog klijenta</span>
</div>
</div>
</div>
<table class="table table-striped table-hover">
<thead>
<tr>
<th>Ime</th>
<th>Prezime</th>
<th>Datum rođenja</th>
<th>Email roditelja</th>
<th>Tel.roditelja</th>
<th>U terapiji?</th>
<th>Dijagnoza</th>
<th>Komentar</th>
<th>Logoped</th>
<th>Akcije</th>
</tr>
</thead>
<tbody>
#foreach($clients as $client)
<tr>
<td>{{$client->name}}</td>
<td>{{$client->lastname}}</td>
<td>{{$client->date_of_birth}}</td>
<td>{{$client->email}}</td>
<td>{{$client->telephone}}</td>
<td>{{$client->in_therapy}}</td>
<td>{{$client->diagnosis}}</td>
<td>{{$client->comments}}</td>
<td>{{$client->therapists_id}}</td>
<td>
<i class="material-icons" data-toggle="tooltip" title="Edit"></i>
<i class="material-icons" data-toggle="tooltip" title="Delete"></i>
</td>
</tr>
#endforeach
</tbody>
</table>
</div>
<!-- add Modal HTML -->
<div id="addEmployeeModal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<form>
<div class="modal-header">
<h4 class="modal-title">Dodaj klijenta</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
{!! Form::open(['action' =>['ClientsController#store',''],'method'=>'POST','style'=>'width:50%',]) !!}
{{csrf_field()}}
<div class="modal-body">
<div class="form-group">
{{Form::label('name','Ime')}}
{{Form::text('name','',['class'=>'form-control'])}}
</div>
<div class="form-group">
{{Form::label('lastname','Prezime')}}
{{Form::text('lastname','',['class'=>'form-control'])}}
</div>
<div class="form-group">
{{Form::label('date_of_birth','Datum rođenja')}}
{{Form::date('date_of_birth','',['class'=>'form-control'])}}
</div>
<div class="form-group">
{{Form::label('email','Email roditelja')}}
{{Form::text('email','',['class'=>'form-control'])}}
</div>
<div class="form-group">
{{Form::label('telephone','Tel. roditelja')}}
{{Form::text('telephone','',['class'=>'form-control'])}}
</div>
<div class="form-group">
{{Form::label('in_therapy','U terapiji?')}}<br/>
{{Form::checkbox('in_therapy','Da',['class'=>'form-control'])}}Da<br/>
{{Form::checkbox('in_therapy','Ne',['class'=>'form-control'])}}Ne<br/>
</div>
<div class="form-group">
{{Form::label('diagnosis','Dijagnoza')}}
{{Form::textarea('diagnosis','',['class'=>'form-control','rows' => 3, 'cols' => 170,])}}
</div>
<div class="form-group">
{{Form::label('comments','Komentari')}}
{{Form::textarea('comments','',['class'=>'form-control','rows' => 3, 'cols' => 170,])}}
</div>
<div class="form-group">
{{Form::label('user_id', 'Logoped')}}<br/>
{{Form::select('user_id', $sp_therapist, null, ['class' => 'form-control','placeholder' => 'Izaberite logopeda'])}}
</div>
</div>
<div class="modal-footer">
<input type="button" class="btn btn-default" data-dismiss="modal" value="Odustani">
<input type="submit" class="btn btn-success" value="Dodaj">
</div>
{!!Form::close()!!}
</div>
</div>
</div>
<!-- Edit Modal HTML -->
<div id="editEmployeeModal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<form>
<div class="modal-header">
<h4 class="modal-title">Edit Employee</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
{!! Form::open(['action' =>['ClientsController#update',''],'method'=>'POST','style'=>'width:50%',]) !!}
{{csrf_field()}}
<div class="modal-body">
<div class="form-group">
{{Form::label('name', 'Ime')}}
{{Form::text('name', $client->name, ['class' => 'form-control'])}}
</div>
<div class="form-group">
{{Form::label('lastname', 'Prezime')}}
{{Form::text('lastname', $client->lastname, ['class' => 'form-control', 'placeholder' ])}}
</div>
<div class="form-group">
{{Form::label('date_of_birth', 'Datum rođenja')}}
{{Form::date('date_of_birth', $client->date_of_birth, ['class' => 'form-control', 'placeholder' => 'Unesite datum rođenja djeteta'])}}
</div>
<div class="form-group">
{{Form::label('email', 'Email')}}
{{Form::text('email', $client->email, ['class' => 'form-control', 'placeholder' => 'Unesite email roditelja'])}}
</div>
<div class="form-group">
{{Form::label('telephone', 'Kontakt broj:')}}
{{Form::text('telephone', $client->telephone, ['class' => 'form-control', 'placeholder' => 'Unesite kontakt broj'])}}
</div>
<div class="form-group">
#if($client->in_therapy != 1)
<div class="form-group">
{{Form::label('in_therapy', 'U terapiji')}}<br>
#if($client->in_therapy == "Da")
{{Form::checkbox('in_therapy', 'Da',$client->in_therapy)}} Da <br>
{{Form::checkbox('in_therapy', 'Ne','')}} Ne<br>
#elseif($client->in_therapy == "Ne")
{{Form::checkbox('in_therapy', 'Da',)}} Da<br>
{{Form::checkbox('in_therapy', 'Ne',$client->in_therapy)}} Ne <br>
#endif
</div>
</div>
#else
<div class="form-group">
{{Form::label('in_therapy', 'U terapiji?')}}<br>
#if($client->in_therapy == "Da")
{{Form::text('in_therapy',$client->in_therapy,['class'=>'form-control','readonly '])}} <br>
#elseif($client->in_therapy == "Ne")
{{Form::text('in_therapy',$client->in_therapy,['class'=>'form-control','readonly '])}} <br>
</div>
#endif
<div class="form-group">
{{Form::label('in_therapy', 'U terapiji?')}}<br>
#if($client->in_therapy == "Da")
{{Form::text('in_therapy',$client->in_therapy,['class'=>'form-control','readonly '])}} <br>
#elseif($client->in_therapy == "Ne")
{{Form::text('in_therapy',$client->in_therapy,['class'=>'form-control','readonly '])}} <br>
</div>
#endif
#endif
<div class="form-group">
{{Form::label('diagnosis', 'Dijagnoza?')}}<br/>
{{Form::textarea('diagnosis', $client->diagnosis, ['class' => 'form-control', 'rows' => 5, 'cols' => 170])}}
</div>
<div class="form-group">
{{Form::label('comments', 'Komentari')}}<br/>
{{Form::textarea('comments', $client->comments, ['class' => 'form-control', 'rows' => 5, 'cols' => 170, 'placeholder' => 'Unesite popratne komentare'])}}
</div>
<div class="form-group">
{{Form::label('therapists_id', 'Logoped')}}
{{Form::select('therapists_id', $sp_therapist, $client->therapists_id,['class' => 'form-control', 'placeholder' => 'Izaberite logopeda'])}}
</div>
</div>
<div class="modal-footer">
<input type="button" class="btn btn-default" data-dismiss="modal" value="Cancel">
<input type="submit" class="btn btn-info" value="Save">
</div>
{!!Form::close()!!}
</div>
</div>
</div>
<!-- Delete Modal HTML -->
<div id="deleteEmployeeModal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
{!!Form::open(['action' =>['ClientsController#destroy', $client->id], 'method' => 'POST'])!!}
<div class="modal-header">
<h4 class="modal-title">Izbriši klijenta</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
<p>Da li ste sigurni da želite izbrisati ovog klijenta?</p>
<p class="text-warning"><small style="color: #000">Ova akcija se ne može poništiti</small></p>
</div>
<div class="modal-footer">
#method('DELETE')
<input type="button" class="btn btn-default" data-dismiss="modal" value="Odustani">
<input type="submit" class="btn btn-danger" value="Izbriši">
</div>
{!!Form::close()!!}
</div>
</div>
</div>
</body>
</html>
#endsection
this is controller for store and edit.
public function store(Request $request)
{
$this->validate($request,[
'name' => 'required',
'lastname' => 'required',
'date_of_birth' => 'required',
'telephone' => 'required'
]);
$client = new Client;
$client->name = $request->input('name');
$client->lastname = $request->input('lastname');
$client->date_of_birth = $request->input('date_of_birth');
$client->email = $request->input('email');
$client->telephone = $request->input('telephone');
$client->in_therapy = $request->input('in_therapy');
$client->diagnosis = $request->input('diagnosis');
$client->comments = $request->input('comments');
$client->therapists_id = $request->input('user_id');
$client->save();
return redirect('/clients')->with('success', 'Klijent je unesen');
}
public function edit($id)
{
$sp_therapist = DB::table('users')->pluck('name', 'id');
$client = Client::find($id);
return view('clients.edit')->with('client',$client)->with('sp_therapist', $sp_therapist);
}
and this is web.php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\FullCalenderController;
use App\Http\Controllers\Auth\RegisterController;
Auth::routes();
Route::group(['middleware' => 'auth'], function () {
Route::get('/','PagesController#index');
Route::get('/dashboard', 'DashboardController#index')->name('dashboard');
Route::get('/register', 'Auth\RegisterController#create')->name('register');
Route::resource('clients','ClientsController');
//CALENDAR
Route::get('schedule', [FullCalenderController::class, 'index']);
Route::post('schedule/action', [FullCalenderController::class, 'action']);
});
thanks
Check that the Modals you're using have the $fillable property with the values you want to insert, something like this:
class User extends Model {
protected $fillable = ['name', 'lastname', 'email']
}
otherwise Eloquent doesn't allow you to inject the inputs.
first if u use laravel 8 use this on ur web.php
use App\Http\Controllers\ClientsController;
Route::resource('clients',[ClientsController::class]);
and in ur index file set form action to route('clients.store') , use route name
in ur store controller try to dd($request) to see the respond, if u still have any problem, let us know
I'm working on a MVC 4 exercise project where I've multiple partial views and when I submit on one of this the entire page validates. I want that every button validates only their own forms.
The page looks like this:
This a partial views example:
#model Money.Models.Category
<script src="~/Scripts/jquery-1.7.1.min.js"></script>
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
#using (Html.BeginForm("Create", "Category", FormMethod.Post, new { id = "createCategoryForm" }))
{
#Html.ValidationSummary(true)
<fieldset>
<legend>Category</legend>
<div class="editor-label">
#Html.LabelFor(model => model.Name)
</div>
<div class="editor-field">
#Html.EditorFor(model => model.Name)
#Html.ValidationMessageFor(model => model.Name)
</div>
<p>
<input id="createCategorySubmit" type="submit" value="Create" />
</p>
</fieldset>
}
And this a part of the entire view:
#model Money.Models.Transaction
#{
ViewBag.Title = "Create";
}
<h2>Create</h2>
#using (Html.BeginForm()) {
#Html.ValidationSummary(true)
<fieldset>
<legend>Transaction</legend>
<div class="editor-label">
#Html.LabelFor(model => model.CategoryId, "Category")
</div>
<div class="editor-field">
#Html.DropDownList("CategoryId", String.Empty)
#Html.ValidationMessageFor(model => model.CategoryId)
</div>
<div id="createCategory">
#Html.Partial("~/Views/Shared/_CreateCategory.cshtml")
</div>
<div class="editor-label">
#Html.LabelFor(model => model.AccountId, "Accout")
</div>
<div class="editor-field">
#Html.DropDownList("AccountId", String.Empty)
#Html.ValidationMessageFor(model => model.AccountId)
</div>
<div id="createAccount">
#Html.Partial("~/Views/Shared/_CreateAccount.cshtml")
</div>
Have you some idea?
Thank you
You have to parse the new content with the validator:
$('form').data('validator', null);
$.validator.unobtrusive.parse($('form'));
How can i trigger the submit button from partial view without using Html.BeginForm tag in Partial View. Reason being when there are two form tags, that is in main view and partial view, the validation doesn't work.
The important thing is that I want the validation to work.
My Partial View code:
<div id="AddMe">
<div class="row">
#Html.LabelFor(model => model.FirstName)
#Html.TextBoxFor(model => model.FirstName)
#Html.ValidationMessageFor(model => model.FirstName) // this should work
</div>
</div>
<div>
<input name="submit" type="submit" id="submit" value="Save" /> // how do i trigger this from partial view
</div>
My Main View code:
#using (Html.BeginForm("ActionName", "ControllerName", FormMethod.Post))
{
<div class="modal" id="modalId" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
</div>
<div class="modal-body" id="modalbodyId">
#Html.Partial("PartilViewName")
</div>
<div class="modal-header">
<button type="submit">
</div>
</div>
</div>
</div>
}
For Validation purpose, I have added the following lines of code in Main View.
$("#modalId").click(function () {
var form = $("#modalbodyId").closest("form");
form.removeData('validator');
form.removeData('unobtrusiveValidation');
$.validator.unobtrusive.parse(form);
$.ajax({
url: "/ControllerName/ActionName",
type: "POST",
data: $("#modalbodyId").serialize(),
cache: false
});
});
Also just for the records all the models and other Annotations are in place.
Note: Do i need to add the unobtrusive/ajax code inside Partial View.
I have view that display Companies' CardView.Every card has add new BankAccount button to display "Add new bank account" modal popup. My view as follow:
#for (int i = 0; i < Model.Companies.Count(); i += 3)
{
<div class="row-fluid">
<div class="span4">
<div class="box corner-all">
<div class="box-header grd-white">
<div class="header-control">
<div>
<ul class="breadcrumb-nav pull-right">
<li class="btn-group">
<a href="#" class="btn btn-small btn-link dropdown-toggle" data-toggle="dropdown">
<i class="icofont-cogs"></i>Controls
<i class="icofont-caret-down"></i>
</a>
<ul class="dropdown-menu">
<li>Add new bankaccount</li>
<li>#Html.ActionLink("Edit", "Edit", Model.Companies.ElementAt(i), new { target = "_blank" })</li>
</ul>
</li>
</ul>
#{Html.RenderPartial("BankCreateModal", new BankAccountCreateViewModel { BankAccount = new Invoice.Model.BankAccount(), TaxTypes = Model.TaxTypes, CompanyID = Model.Companies.ElementAt(i).ID });}
</div>
</div>
<span>#Model.Companies.ElementAt(i).ShortName</span>
</div>
<div class="box-body">
<table>
<tr>
<td rowspan="2">
<div class="resume-photo">
<img src="~/Content/img/LogoFiles/#Model.Companies.ElementAt(i).LogoFile" style="width: 50px; height: 45px;"/>
</div>
</td>
<td>#Model.Companies.ElementAt(i).FullName</td>
</tr>
</table>
<div class="alert alert-info">
#*<button type="button" class="close" data-dismiss="alert">×</button>*#
<strong></strong>#Model.Companies.ElementAt(i).CompanyDescription
</div>
</div>
<div style="text-align: center; padding-left: 22px;">
<div class="thumbnails pricing-table color-black">
<div class="span3 active grd-white box-shadow" style="width: 270px;">
<div class="bank_details_expand">
<div class="features">
<div id="slideshow-area">
<div id="slideshow-previous"></div>
<div id="slideshow-next"></div>
<div id="slideshow-scroller">
<div id="slideshow-holder">
#foreach (var bank in Model.BankAccounts.ElementAt(i))
{
<div class="slideshow-content">
<div class="alert alert-info">
<!--box body-->
<div class="box-body">
<!-- Button to trigger modal -->
<!-- Modal -->
#{Html.RenderPartial("BankEditModal", new BankAccountEditViewModel { BankAccount = bank, TaxTypes = Model.TaxTypes });}
</div>
<!--/box body-->
<ul style="text-align: left;">
<li></li>
<li><span style="font-weight: bolder; color: #0B72E0">Bank Name:</span>
<span style="font-style: italic;">#bank.BankName</span></li>
<li><span style="font-weight: bolder; color: #0B72E0">Corr. Account:</span>
<span style="font-style: italic;">#bank.CorrespondentAccount</span> </li>
<li><span style="font-weight: bolder; color: #0B72E0">IBAN:</span>
<span style="font-style: italic;">#bank.IBAN </span></li>
<li><span style="font-weight: bolder; color: #0B72E0">Code:</span>
<span style="font-style: italic;">#bank.Code</span></li>
<li><span style="font-weight: bolder; color: #0B72E0">SWIFT:</span>
<span style="font-style: italic;">#bank.SWIFT</span></li>
<li><span style="font-weight: bolder; color: #0B72E0">Tax Type:</span>
<span style="font-style: italic;">#bank.Tax.Presentage % </span></li>
</ul>
</div>
</div>
}
</div>
</div>
</div>
</div>
</div>
<div class="bank-details-control">
<div class="footer grd-white" data-box="expandBank">
<div>Bank Details</div>
<i class="icofont-chevron-down"></i>
#*<a class="btn btn-block btn-warning" data-box="expandBank">Bank Details</a>*#
</div>
</div>
</div>
</div>
</div>
</div>
</div>
#if (Model.Companies.Count() - 1 > i)
{
#{Html.RenderPartial("BankCreateModal", new BankAccountCreateViewModel { BankAccount = new Invoice.Model.BankAccount(), TaxTypes = Model.TaxTypes, CompanyID = Model.Companies.ElementAt(i + 1).ID });}
}
#if (Model.Companies.Count() - 2 > i)
{
#{Html.RenderPartial("BankCreateModal", new BankAccountCreateViewModel { BankAccount = new Invoice.Model.BankAccount(), TaxTypes = Model.TaxTypes, CompanyID = Model.Companies.ElementAt(i + 2).ID });}
}
}
PartialView for create bankaccount as follow
#model InvoiceModel.HelperClasses.BankAccountCreateViewModel
<script src="~/Scripts/jquery-1.7.1.min.js"></script>
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
<div id="MyCreate" class="modal hide fade" tabindex="-1" role="dialog" aria- labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h2 id="myModalLabel">Bank Account</h2>
</div>
<div class="modal-body">
#using (Ajax.BeginForm("CreateModal", new AjaxOptions { UpdateTargetId = "Createmodal", HttpMethod = "Post" }))
{
#Html.ValidationSummary(true)
#Html.HiddenFor(model => model.CompanyID)
#Html.HiddenFor(model => model.TaxTypes)
<div class="control-group">
#Html.LabelFor(model => model.BankAccount.BankName)
#Html.EditorFor(model => model.BankAccount.BankName)
#Html.ValidationMessageFor(model => model.BankAccount.BankName)
</div>
<div class="control-group">
#Html.LabelFor(model => model.BankAccount.CorrespondentAccount)
#Html.EditorFor(model => model.BankAccount.CorrespondentAccount)
#Html.ValidationMessageFor(model => model.BankAccount.CorrespondentAccount)
</div>
<div class="control-group">
#Html.LabelFor(model => model.BankAccount.IBAN)
#Html.EditorFor(model => model.BankAccount.IBAN)
#Html.ValidationMessageFor(model => model.BankAccount.IBAN)
</div>
<div class="control-group">
#Html.LabelFor(model => model.BankAccount.Code)
#Html.EditorFor(model => model.BankAccount.Code)
#Html.ValidationMessageFor(model => model.BankAccount.Code)
</div>
<div class="control-group">
#Html.LabelFor(model => model.BankAccount.SWIFT)
#Html.EditorFor(model => model.BankAccount.SWIFT)
#Html.ValidationMessageFor(model => model.BankAccount.SWIFT)
</div>
<div class="control-group">
#Html.LabelFor(model => model.BankAccount.TaxID, new { #class = "control-label" })
<div class="controls">
#Html.DropDownListFor(model => model.BankAccount.TaxID, new SelectList(Model.TaxTypes, "ID", "Name"), new { data_placeholder = "Select Tax Type", data_form = "select2" })
#Html.ValidationMessageFor(model => model.BankAccount.TaxID)
</div>
</div>
<button class="btn btn-primary">Save changes</button>
}
</div>
<div class="modal-footer">
<button class="btn btn-danger" data-dismiss="modal" aria-hidden="true">Close</button>
</div>
So, When I click SaveChanges button I can create new bank for first company, but when click for other company in bankaccountcontroller my CompanyID is the same with first company. My HTTPPOST action as follow
[HttpPost]
public ActionResult CreateModal(BankAccountCreateViewModel bank)
{
bank.BankAccount.CompanyID = bank.CompanyID;
bankRepository.SaveBankAccount(bank.BankAccount);
return RedirectToActionPermanent("Index");
}
How can I fix this problem? I need second or other companyID, not first.