I am trying to save image in asp.net mvc but everytime I pass the value I am getting null value in httppostedfilebase parameter in controller in post method. How am I supposed to solve this? I have searched for the answer but non of the answer on internet were helpful.
My Controller Code:
[HttpPost]
public ActionResult Products(ItemDTO itemDTO,HttpPostedFileBase Picture1)
{
itemDTO.OrderItems = null;
var folder = this.Server.MapPath("~/Images/");
string newGuid = Guid.NewGuid().ToString();
string pathToCreate = Path.Combine(folder);
if (!System.IO.Directory.Exists(pathToCreate))
{
System.IO.Directory.CreateDirectory(System.IO.Path.Combine(folder));
}
//var fileName = pathToCreate + "//" + System.IO.Path.GetFileName(Picture1File.FileName);
var imageName = newGuid + System.IO.Path.GetExtension(System.IO.Path.GetFileName(Picture1.FileName));
var fileName = pathToCreate + imageName;
Picture1.SaveAs(fileName);
//itemDTO.imageName = imageName;
//....and update the database itemDTO
try
{
if (itemDTO.ItemId == 0)
{
List<ItemDTO> items = new List<ItemDTO>();
//Dictionary<string, string> postParams = new Dictionary<string, string>();
IRestResponse response = APIHelper.InvokePOSTMethod(Constants.CreateItem, itemDTO);
if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
items = new JavaScriptSerializer().Deserialize<List<ItemDTO>>(response.Content);
}
//ViewBag.Error = "Data save successsful!";
else
ViewBag.Error = response.Content;
}
else
{
//List<ItemDTO> item = new List<ItemDTO>();
//Dictionary<string, string> dict = new Dictionary<string, string>();
//dict.Add("id", itemDTO.ToString());
IRestResponse response = APIHelper.InvokePOSTMethod(Constants.UpdateItem, itemDTO);
if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
List<ItemDTO> item = new List<ItemDTO>();
item = new JavaScriptSerializer().Deserialize<List<ItemDTO>>(response.Content);
}
//ViewBag.Error = "Data save successsful!";
else
ViewBag.Error = response.Content;
}
}
catch (Exception ex)
{
//Log.Error(ex);
return Json("false", JsonRequestBehavior.AllowGet);
}
return Json("true", JsonRequestBehavior.AllowGet);
}
My Model Class:
public class ItemDTO
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public ItemDTO()
{
this.OrderItems = new HashSet<OrderItem>();
}
public int ItemId { get; set; }
public string ItemCategory { get; set; }
public string ItemName { get; set; }
public Nullable<decimal> Price { get; set; }
public string Picture1 { get; set; }
public string Desctiption { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<OrderItem> OrderItems { get; set; }
}
My View:
<form id="AddProduct" class="needs-validation" novalidate method="post" enctype="multipart/form-data">
<div class="wrapper">
<div class="main-panel">
#Html.HiddenFor(x => x.ItemId)
<div class="content">
<div class="row" id="frmAddProduct">
<div class="info-panel">
<div id="form-mode">
</div>
#*<div id="validation-summary">Please provide values for the highlighted fields.</div>*#
</div>
<div class="col-md-3">
<div class="card">
<div class="card-header card-menu py-3">
Add Products
<div class="headerRightFeatures">
<img src="~/Content/assets/img/delete.png" alt="" id="delete">
</div>
</div>
<div class="card-body">
<div class="form-row">
<div class="col-md-12 mb-3">
<label for="ItemName">Category</label>
#Html.EditorFor(model => model.ItemCategory, new { htmlAttributes = new { #class = "form-control" } })
<div class="invalid-feedback">
Please provide a valid product name.
</div>
</div>
</div>
<div class="form-row">
<div class="col-md-12 mb-3">
<label for="ItemName">Product Name</label>
#Html.EditorFor(model => model.ItemName, new { htmlAttributes = new { #class = "form-control" } })
<div class="invalid-feedback">
Please provide a valid product name.
</div>
</div>
</div>
<div class="form-row">
<div class="col-md-12 mb-3">
<label for="Price">Price</label>
#Html.EditorFor(model => model.Price, new { htmlAttributes = new { #class = "form-control" } })
<div class="invalid-feedback">
Please provide a valid price.
</div>
</div>
</div>
<div class="form-row">
<div class="col-md-12 mb-3">
#Html.LabelFor(model => model.Picture1)
<input type="file" id="Picture1" name="Picture1" />
</div>
</div>
<div class="form-row">
<div class="col-md-12 mb-3">
<label for="Price">Description</label>
#Html.EditorFor(model => model.Desctiption, new { htmlAttributes = new { #class = "form-control" } })
<div class="invalid-feedback">
Please provide a valid price.
</div>
</div>
</div>
<div class="wAuto button-wrapper fleft">
<input type="button" value="Save" class="btn btn-primary btn-sm" id="btn-submit-product" />
<input type="button" value="Cancel" class="btn btn-primary btn-sm" id="btn-cancel-product" />
</div>
</div>
</div>
</div>
</div>
<table id="productlisting" class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th>Item Id</th>
<th>Item Category</th>
<th>Item Name</th>
<th>Picture1</th>
<th>Price</th>
<th>Description</th>
</tr>
</thead>
</table>
Use submit button instead of button
Use
<input type="submit" value="Save" class="btn btn-primary btn-sm" id="btn-submit-product" />
instead of
<input type="button" value="Save" class="btn btn-primary btn-sm" id="btn-submit-product" />
HttpPostedFileBase only get value when button type is submit
<form id="AddProduct" class="needs-validation" novalidate method="post" enctype="multipart/form-data">
<div class="wrapper">
#Html.Hidden("ItemId", 2)
<div class="main-panel">
<div class="content">
<div class="row" id="frmAddProduct">
<div class="info-panel">
<div id="form-mode">
</div>
</div>
<div class="col-md-3">
<div class="form-row">
<div class="col-md-12 mb-3">
<input type="file" id="Picture1" name="Picture1" />
</div>
</div>
<div class="wAuto button-wrapper fleft">
<input type="submit" value="Save" class="btn btn-primary btn-sm" id="btn-submit-product" />
</div>
</div>
</div>
</div>
</div>
</div>
</form>
[HttpPost]
public ActionResult Index(int ItemId, HttpPostedFileBase Picture1)
{
return View();
}
Related
How to add dynamically html controls through the Angular Js in Asp.NetMVC Project?
just like-i want to add multiple bank details of employee on add button click.
and how can i remove wrong bank details on other remove button click.
To add dynamically bank details page controls through angular js
Step 1: first of all create html page like below code.
Bank.cshtml page
<form class="form-horizontal" enctype="multipart/form-data">
<div ng-repeat="item in ArrBankCtrls">
<div class="form-group">
<label ng-model="item.bankPK_Id" hidden></label>
<label for="BankName" class="col-sm-2 control-label">Bank <i class="mandatStarColor">*</i></label>
<div class="col-sm-6">
<select class="form-control" style="width: 100%;" ng-change="ChangeBankName()" ng-model="item.BankName">
<option selected="selected">--Select Bank--</option>
<option ng-repeat="item in bankName" value="{{item.Value}}">{{item.Text}}</option>
</select>
<span style="color:red;" ng-show="item.requiredBankName">BankName is required !</span>
</div>
<div class="col-sm-2">
<button id="Add" class="btn btn-success" title="Add" ng-click="AddRemoveBank(true,item)">+</button>
<button class="btn btn-danger" ng-model="RemoveBankCtrl" ng-disabled="RemoveBankCtrl" title="Remove" ng-click="AddRemoveBank(false,item)">-</button>
</div>
</div>
<div class="form-group">
<label for="AccountNo" class="col-sm-2 control-label">A/c No. <i class="mandatStarColor">*</i></label>
<div class="col-sm-6">
<input type="text" class="form-control" onlydigits ng-change="ChangeAccountNo($index)" ng-model="item.AccountNo" placeholder="Account No." maxlength="26" required>
<span style="color:red;" ng-show="item.requiredAccountNo">AccountNo is required !</span>
</div>
</div>
<div class="form-group">
<label for="IFSC" class="col-sm-2 control-label">IFSC <i class="mandatStarColor">*</i></label>
<div class="col-sm-6">
<input type="text" class="form-control" ng-change="ChangeIFSC($index)" ng-model="item.IFSC" placeholder="IFSC" maxlength="11" required>
<span style="color:red;" ng-show="item.requiredIFSC">IFSC is required !</span>
<span style="color:red;" ng-show="item.requiredDigitIFSC">Required 11 digit's !</span>
</div>
</div>
<div class="form-group">
<label for="Address" class="col-sm-2 control-label">Address</label>
<div class="col-sm-6">
<input type="text" class="form-control" ng-model="item.Address" placeholder="Address">
</div>
</div>
<div class="form-group">
<label for="CancelCheque" class="col-sm-2 control-label">Cancel Cheque <i class="mandatStarColor">*</i></label>
<div class="col-sm-6">
<input type="file" id="{{ 'CancelCheque-' + this.$index }}" ng-file-select="onFileSelect($files)" onchange="angular.element(this).scope().BankFileChange(this)" ng-model="item.ImgCancelCheque" upload-file="item.CancelCheque" accept=".pdf,.gif,.jpg,.jpeg,.png,.bmp">
<span style="color:red;" ng-show="item.requiredCancelCheque">CancelCheque file is required !</span>
<img src="{{item.ImgCancelCheque}}" alt="Cancel Cheque" class="imgHeightWidth" />
</div>
</div>
</div>
</form>
Angular Js code
//#region To Add/Remove BankDetails controls
$scope.RemoveBankCtrl = true;
$scope.ArrBankCtrls = [{
PK_Id: "",
BankName: "",
AccountNo: "",
IFSC: "",
Address: "",
CancelCheque: ""
}];
$scope.AddRemoveBank = function (flag, item) {
//debugger
var index = this.$index;
if (flag) {
item = { PK_Id: "", BankName: "", AccountNo: "", IFSC: "", Address: "", CancelCheque: "" };
$scope.ArrBankCtrls.push(item);
$scope.RemoveBankCtrl = false;
//#region Set default selected value in ddl
$scope.ArrBankCtrls[($scope.ArrBankCtrls.length - 1)].BankName = "--Select Bank--";
// #endregion
}
else {
//$scope.ArrBankCtrls.pop(item);
$scope.ArrBankCtrls.splice(index, 1);
if ($scope.ArrBankCtrls.length == 1) {
$scope.RemoveBankCtrl = true;
}
}
}
//#region Bind Bank Name ddl
$scope.ArrBankCtrls[0].BankName = "--Select Bank--";
VendorService.postData(strVenUrl + "/GetBank").then(function (data) {
if (data != null) {
$scope.bankName = data;
}
})
// #endregion
// #endregion
Controller.cs Code
#region GetBank
public ActionResult GetBank()
{
dynamic bank = null;
try
{
bank = vendor.Bank();
}
catch (Exception ex)
{
ExceptionError(ex.Message);
}
return Json(bank, JsonRequestBehavior.AllowGet);
}
#endregion
[HttpPost]
public ActionResult InsertBankDetails(List<BankDetails> bankDetails)
{
//Your code
return RedirectToAction("BankDetails");
}
you must have used somewhere collections, bind that collection in the ng-repeat directive, on the button click and add simply remove and add an item from the collection
i am developing angular app with webapi 2, have input form it contains input values. i encapsulate input values into an object "ALBUM" pass to angular post method
enter code here
<form>
<div class="form-group row">
<label for="inputAName" class="col-sm-3 col-form-label">Album Name</label>
<div class="col-sm-8">
<input type="text" class="form-control" id="inputEmail3" placeholder="AlbumName" ng-model="album.Albm_Name">
</div>
</div>
<div class="form-group row">
<label for="inputPassword3" class="col-sm-3 col-form-label">Music Artist</label>
<div class="col-sm-8">
<select ng-model="album.Aritist_id">
<option ng-repeat="Artist in Artists" value="{{Artist.Artist_id}}">{{Artist.Artist_Name}}</option>
</select>
</div>
</div>
<div class="form-group row">
<label for="inputRdate" class="col-sm-3 col-form-label">Released Date</label>
<div class="col-sm-8">
<input type="date" class="form-control" id="inputPassword3" placeholder="date" ng-model="album.RelaeseDate">
</div>
</div>
<div class="form-group row">
<label for="inputImg" class="col-sm-3 col-form-label">Image of Album</label>
<div class="col-sm-8">
<input type="file" class="form-control-file" id="exampleInputFile" aria-describedby="fileHelp" name="file"
ng-model="album.picture" base-sixty-four-input required onload="onLoad" maxsize="500" accept="image/*">
</div>
</div>for
<div class="form-group row">
<div class="col-sm-offset-9 col-sm-2">
<button type="submit" class="btn btn-primary" ng-click="insertAlbum(album)">Save</button>
</div>
</div>
</form>
above code , ng-model='album.picture' return an object which contains more values "attached image file"
i need to filter album.picture only contain base64 string value, how do i do
without breaking the album object from view
$scope.insertAlbum = function (album) {
var urlAlbum = 'http://localhost:8090/api/album';
dataService.insertObject(urlAlbum, album).then(function (responce) {
alert("Success");
}, function (eror) {
alert(eror.message);
});
}
public partial class tblAlbum
{
public tblAlbum()
{
this.tblTracks = new HashSet<tblTrack>();
}
public int Albm_id { get; set; }
public Nullable<int> Aritist_id { get; set; }
public string Albm_Name { get; set; }
public Nullable<System.DateTime> RelaeseDate { get; set; }
public byte[] picture { get; set; }
public virtual tblArtist tblArtist { get; set; }
public virtual ICollection<tblTrack> tblTracks { get; set; }
}
just i found a solution
here it is :
$scope.insertAlbum = function (album) {
var urlAlbum = 'http://localhost:8090/api/album';
album.picture = $scope.file.base64;
dataService.insertObject(urlAlbum, album).then(function (responce) {
alert("Success");
}, function (eror) {
alert(eror.message);
});
}
manually i created an picture property and asigned views input value using $scope
Am using the new implementation of uploading files which is the IFormFile. I created a view model and mapped it on a model, however, I am getting a null value on the ImageFile property of the view model. In inserting the record, I am using AngularJS to prevent it from reloading. Below is my views and controller.
public string CreateNewProduct([FromBody] ProductViewModel _product)
{
var imgFile = _product.ImageFile;
var fileName = ContentDispositionHeaderValue.Parse(imgFile.ContentDisposition).FileName.Trim('"');
var targetDirectory = Path.Combine(environment.WebRootPath, string.Format("Common\\Images\\"));
var savePath = Path.Combine(targetDirectory, fileName);
imgFile.CopyTo(new FileStream(savePath, FileMode.Create));
Products product = new Products
{
ItemCode = _product.ItemCode,
FileName = fileName,
FilePath = savePath
};
context.Products.Add(product);
context.SaveChanges();
return "";
}
And here is my view in a dialog box.
<div class="modal" role="dialog" id="addItemDialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h3 class="text-info">Add New Item</h3>
</div>
<div class="modal-body">
<form id="newproductform" class="form-horizontal" role="form" enctype="multipart/form-data">
<div class="form-group">
<span class="col-sm-3 control-label">Item Code</span>
<div class="col-sm-6">
<input type="text" class="form-control input-sm" ng-model="ItemCode" />
</div>
</div>
<div class="form-group">
<span class="col-sm-3 control-label">Image</span>
<input type="file" name="file" accept="image/*" onchange="angular.element(this).scope().selectFileforUpload(this.files)" required />
<span class="error" ng-show="(f1.file.$dirty || IsFormSubmitted) && f1.file.$error.required">Image required!</span>
</div>
</form>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-success" ng-click="InsertProduct()">Submit</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
I just used the submit button but still I get null value on ImageFile property on the view model.
Here is my view model.
public class ProductViewModel
{
public string ItemCode { get; set; }
//[FileExtensions(Extensions = "jpg/jpeg")]
public IFormFile ImageFile { get; set; }
}
Here I am using ng-blur for checking if email exits or not.It is working as I expected but why it's not getting validated in ng-show.
<form name="f1" novalidate ng-submit="Save(emp)">
<div class="form-group">
<div class="row">
<div class="col-sm-4">
<b style="font-family: Arial; text-transform: capitalize; text-align:left ">Enter EmailId</b>
</div>
<div class="col-sm-8 left-addon">
<input type="email" class="form-control" name="Mail" ng-model="Eamil" ng-blur="ChkAvailableEmail()" ng-class="submitted?'ng-dirty':''" required />
<i class="glyphicon glyphicon-envelope"></i>
<span class="Error" ng-show="(f1.Mail.$dirty ||submitted) && f1.Mail.$error.email">Please Enter Your Valied Email</span>
<span class="Error" ng-show="f1.Mail.$error.ChkAvailableEmail">Email in Use Please try new one</span>
</div>
</div>
</div>
</form>
AngularJs
$scope.ChkAvailableEmail = function () {
var chk = {
Email: $scope.Eamil
}
var mail = $Myservice.GetValidEmail(chk);
mail.then(function (d) {
})
}
HomeController.cs
public JsonResult ChkEmail(string Email)
{
var x = (from n in db.Accessors
where n.Email == Email
select n).FirstOrDefault();
return new JsonResult { Data = x, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
}
I have a input datetime and I am passing dates on it.
Whatever value I pass but its always giving "01/01/0001 00:00:00".
Below is the code I have used. I am calling AddUpdateEmployee() on form ng-submit.
Model:-
public partial class Employee
{
public int Id { get; set; }
public string name { get; set; }
public DateTime DOB { get; set; }
public string Gender { get; set; }
public string Email { get; set; }
public string Mobile { get; set; }
public string Address { get; set; }
public DateTime JoiningDate { get; set; }
public int DepartmentID { get; set; }
public int DesignationID { get; set; }
}
View :-
<form name="form.userForm" ng-submit="AddUpdateEmployee()" novalidate >
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">{{Action}} Employee Details</h4>
</div>
<div class="modal-body">
<div class="form-horizontal validationcheck">
<div class="form-group">
<div class="row">
<div class="col-md-2 col-sm-2" style="margin-left: 20px; color: #5bc0de;">
<b>Name :</b>
</div>
<div class="col-md-8 col-sm-8">
<input type="text" class="form-control" data-modal="modal" filter="anything" ng-model="employeeName" placeholder="Employee's Name" ng-required="true" required="required" />
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-md-2 col-sm-2" style="margin-left: 20px; color: #5bc0de;">
<b>DOB :</b>
</div>
<div class="col-md-8 col-sm-8">
<input type="datetime" class="form-control myCalendar" ng-model="employeeDOB" data-modal="modal" ng-required="true" />
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-md-2 col-sm-2" style="margin-left: 20px; color: #5bc0de;">
<b>Gender:</b>
</div>
<div class="col-md-8 col-sm-8" ng-required="true">
<input type="radio" title="Male" data-modal="modal" ng-model="employeeGender" value="Male" />
Male
<input type="radio" title="Female" data-modal="modal" ng-model="employeeGender" value="Female" />
Female
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-md-2 col-sm-2" style="margin-left: 20px; color: #5bc0de;">
<b>Email:</b>
</div>
<div class="col-md-8 col-sm-8">
<input type="email" class="form-control" data-modal="modal" ng-model="employeeEmail" placeholder="Employee's Email" ng-required="true" />
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-md-2 col-sm-2" style="margin-left: 20px; color: #5bc0de;">
<b>Mobile:</b>
</div>
<div class="col-md-8 col-sm-8">
<input type="text" class="form-control" data-modal="modal" ng-model="employeeMobile" placeholder="Employee's Mobile" ng-required="true" />
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-md-2 col-sm-2" style="margin-left: 20px; color: #5bc0de;">
<b>Address:</b>
</div>
<div class="col-md-8 col-sm-8">
<input type="text" class="form-control" data-modal="modal" ng-model="employeeAddress" placeholder="Employee's Address" ng-required="true" />
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-md-2 col-sm-2" style="margin-left: 20px; color: #5bc0de;">
<b>Joining Date:</b>
</div>
<div class="col-md-8 col-sm-8">
<input type="datetime" class="form-control myCalendar" data-modal="modal" ng-model="employeeJoiningDate" ng-required="true" />
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-md-2 col-sm-2" style="margin-left: 20px; color: #5bc0de;">
<b>Department:</b>
</div>
<div class="col-md-8 col-sm-8">
<select id="ddlDepartment" class="form-control ddlDepartment" data-modal="modal" ng-model="employeeDepartment" ng-options="dep.Id as dep.DepartmentName for dep in departments" ng-required="true">
<option value="" selected>--Select Department--</option>
#* <option data-ng-repeat="dep in departments" value="{{dep.Id}}">{{dep.DepartmentName}}</option>*#
</select>
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-md-2 col-sm-2" style="margin-left: 20px; color: #5bc0de;">
<b>Designation:</b>
</div>
<div class="col-md-8 col-sm-8">
<select id="ddlDesignation" class="form-control ddlDesignation" data-modal="modal" ng-model="employeeDesignation" ng-options="dsg.Id as dsg.DesignationName for dsg in designations" ng-required="true">
<option value="" selected>--Select Designation--</option>
</select>
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-md-2 col-sm-2" style="margin-left: 20px; color: #5bc0de;"></div>
<div class="col-md-8 col-sm-8">
</div>
</div>
</div>
</div>
<div class="modal-footer">
<input type="submit" class="btnAdd btn btn-success" value="Save" ng-disabled="form.userForm.$invalid" />
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
</form>
Controller:-
public string UpdateEmployee(Employee Emp)
{
if (Emp != null)
{
using (EmpEntities dataContext = new EmpEntities())
{
int no = Convert.ToInt32(Emp.Id);
var employeeList = dataContext.Employees.Where(x => x.Id == no).FirstOrDefault();
employeeList.name = Emp.name;
employeeList.DOB = Emp.DOB;
employeeList.Gender = Emp.Gender;
employeeList.Email = Emp.Email;
employeeList.Mobile = Emp.Mobile;
employeeList.Address = Emp.Address;
//employeeList.JoiningDate = Convert.ToDateTime(Emp.JoiningDate.ToString("dd/MM/yyyy hh:mm"));
employeeList.JoiningDate = Emp.JoiningDate;
employeeList.DepartmentID = Emp.DepartmentID;
employeeList.DesignationID = Emp.DesignationID;
dataContext.SaveChanges();
return "Employee Updated Successfully";
}
}
else
{
return "Invalid Employee";
}
}
Angular Controller calling its Service:-
$scope.AddUpdateEmployee = function () {
//alert('here');
var Employee = {
Name: $scope.employeeName,
DOB: $scope.employeeDOB,
Gender: $scope.employeeGender,
Email: $scope.employeeEmail,
Mobile: $scope.employeeMobile,
Address: $scope.employeeAddress,
JoiningDate: $scope.employeeJoiningDate,
DepartmentID: $scope.employeeDepartment,
DesignationID: $scope.employeeDesignation
//alert();
};
var getAction = $scope.Action;
if (getAction == "Edit") {
Employee.Id = $scope.employeeId;
var getData = myService.updateEmp(Employee);
getData.then(function (msg) {
// GetAllEmployee();
}
Angular function responding its controller (Angular Service function responding to angular controller):-
this.updateEmp = function (employee) {
var response = $http({
method: "post",
url: "/Employee/UpdateEmployee",
data: JSON.stringify(employee),
dataType: "json"
});
return response;
}
Convert the value of date before you send it for example
if you use date plugin JQuery, etc. set it format to one excepted like dd/mm/yyyy and convert it to what your API excepted format yyyy-mm-dd
// here convert before you sent it with your Angualr Service
var apiDateFormat = Employee.DOB.split('/'); // ["MM", "dd", "yyyy"]
Employee.DOB = apiDateFormat[2]+ '-' +apiDateFormat[0] + '-'+ apiDateFormat[1];
// send it now... $http service