In this method, I want to check that the var Total don't exceed the TotalMonths variable.
The problem is, that the var Total is always received with a value of zero, and I don't understad why. Here the method:
/********EDIT MONTH DETAILS POST*********/
[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult EditMonthDetail(BudgetViewModel budget)
{
//var Total = budget.FBudget.UnitPrice * budget.FBudget.Quantity;
//budget.FBudget.TotalAmount = budget.FBudget.UnitPrice * budget.FBudget.Quantity;
//var Total = _unitOfWork.Budget.Get(budget.FBudget.TotalAmount);
var Total = BudgetVM.FBudget.TotalAmount;
/*Always retrieved with 0*/
if (Total >= budget.FBudget.TotalMonths)
{
_unitOfWork.Budget.EditMonthDetails(BudgetVM.FBudget);
_unitOfWork.Save();
return RedirectToAction("Success");
}
return RedirectToAction("FailedTotal");
}
Here is how the TotalAmount is implemented in the model:
public float TotalAmount
{
get
{
return UnitPrice * Quantity;
}
}
Here is the View with a form of type Post:
#{
Layout = "~/Views/Shared/_Layout.cshtml";
var title = "title";
}
<form method="post" asp-action="EditMonthDetail">
<div class="row px-2 mx-2">
<div class="col-12">
#if (Model.FBudget.BudgetId != 0)
{
<input type="hidden" asp-for="FBudget.BudgetId" />
title = "Edit Month details";
}
<br />
<h2 class="text-primary">#title</h2>
</div>
<br />
<div class="col-8">
<div class="form-group row">
<div class="col-4">
<label asp-for="FBudget.Jan"></label>
</div>
<div class="col-8">
<input asp-for="FBudget.Jan" class="form-control" />
<span asp-validation-for="FBudget.Jan" class="text-danger"></span>
</div>
</div>
</div>
<br />
<br />
<div class="col-8">
<div class="form-group row">
<div class="col-4">
<label asp-for="FBudget.Feb"></label>
</div>
<div class="col-8">
<input asp-for="FBudget.Feb" class="form-control" />
<span asp-validation-for="FBudget.Feb" class="text-danger"></span>
</div>
</div>
</div>
<br />
<br />
<div class="col-8">
<div class="form-group row">
<div class="col-4">
<label asp-for="FBudget.Mar"></label>
</div>
<div class="col-8">
<input asp-for="FBudget.Mar" class="form-control" />
<span asp-validation-for="FBudget.Mar" class="text-danger"></span>
</div>
</div>
</div>
<br />
<br />
<div class="col-8">
<div class="form-group row">
<div class="col-4">
<label asp-for="FBudget.Apr"></label>
</div>
<div class="col-8">
<input asp-for="FBudget.Apr" class="form-control" />
<span asp-validation-for="FBudget.Apr" class="text-danger"></span>
</div>
</div>
</div>
<br />
<br />
<div class="col-8">
<div class="form-group row">
<div class="col-4">
<label asp-for="FBudget.May"></label>
</div>
<div class="col-8">
<input asp-for="FBudget.May" class="form-control" />
<span asp-validation-for="FBudget.May" class="text-danger"></span>
</div>
</div>
</div>
<br />
<br />
<div class="col-8">
<div class="form-group row">
<div class="col-4">
<label asp-for="FBudget.Jun"></label>
</div>
<div class="col-8">
<input asp-for="FBudget.Jun" class="form-control" />
<span asp-validation-for="FBudget.Jun" class="text-danger"></span>
</div>
</div>
</div>
<br />
<br />
<div class="col-8">
<div class="form-group row">
<div class="col-4">
<label asp-for="FBudget.Jul"></label>
</div>
<div class="col-8">
<input asp-for="FBudget.Jul" class="form-control" />
<span asp-validation-for="FBudget.Jul" class="text-danger"></span>
</div>
</div>
</div>
<br />
<br />
<div class="col-8">
<div class="form-group row">
<div class="col-4">
<label asp-for="FBudget.Ago"></label>
</div>
<div class="col-8">
<input asp-for="FBudget.Ago" class="form-control" />
<span asp-validation-for="FBudget.Ago" class="text-danger"></span>
</div>
</div>
</div>
<br />
<br />
<div class="col-8">
<div class="form-group row">
<div class="col-4">
<label asp-for="FBudget.Sept"></label>
</div>
<div class="col-8">
<input asp-for="FBudget.Sept" class="form-control" />
<span asp-validation-for="FBudget.Sept" class="text-danger"></span>
</div>
</div>
</div>
<br />
<br />
<div class="col-8">
<div class="form-group row">
<div class="col-4">
<label asp-for="FBudget.Oct"></label>
</div>
<div class="col-8">
<input asp-for="FBudget.Oct"class="form-control" />
<span asp-validation-for="FBudget.Oct" class="text-danger"></span>
</div>
</div>
</div>
<br />
<br />
<div class="col-8">
<div class="form-group row">
<div class="col-4">
<label asp-for="FBudget.Nov"></label>
</div>
<div class="col-8">
<input asp-for="FBudget.Nov"class="form-control" />
<span asp-validation-for="FBudget.Nov" class="text-danger"></span>
</div>
</div>
</div>
<br />
<br />
<div class="col-8">
<div class="form-group row">
<div class="col-4">
<label asp-for="FBudget.Dec"></label>
</div>
<div class="col-8">
<input asp-for="FBudget.Dec"class="form-control" />
<span asp-validation-for="FBudget.Dec" class="text-danger"></span>
</div>
</div>
</div>
<br />
<br />
<div class="col-8">
<div class="form-group row">
<div class="col-8 offset-4">
<button type="submit" class="btn btn-primary form-control">Update</button>
</div>
</div>
</div>
</div>
</form>
I also tried to create a GetTotalAmount() method in the repository but it doesn't seems to work.
What am I doing wrong here?
EDIT
Here is the model:
namespace SalesBudget.Models
{
public class FBudget
{
[Key]
public int BudgetId { get; set; }
[Required(ErrorMessage = "Year is required.")]
public int Year { get; set; }
[Required(ErrorMessage = "FoC is required.")]
public string FreeOfCharge { get; set; }
[Required(ErrorMessage = "Currency is required.")]
public string Currency { get; set; }
[Required(ErrorMessage = "Unit price is required.")]
[Display(Name = "Unit Price")]
public float UnitPrice { get; set; }
public int Jan { get; set; }
public int Feb { get; set; }
public int Mar { get; set; }
public int Apr { get; set; }
public int May { get; set; }
public int Jun { get; set; }
public int Jul { get; set; }
public int Ago { get; set; }
public int Sept { get; set;}
public int Oct { get; set; }
public int Nov { get; set; }
public int Dec { get; set; }
public int TotalMonths
{
get
{
return Jan + Feb + Mar + Apr + May
+ Jun + Jul + Ago + Sept + Oct + Nov + Dec;
}
}
[Display(Name = "Month Nr")]
[Required(ErrorMessage = "Month Nr is required.")]
[Range(1, 12, ErrorMessage = "The value must be between 1 and 12!")]
public string MonthNr { get; set; }
[Display(Name = "Unit of Measure")]
[Required(ErrorMessage = "Unit of Measure is required.")]
public string UnitOfMeasure { get; set; }
[Display(Name = "Quantity")]
[Required(ErrorMessage = "Quantity in untis is required.")]
public int Quantity { get; set; }
public float TotalAmount
{
get
{
return UnitPrice * Quantity;
}
}
public string LastUser
{
//automatically set the last user that used the app
get; set;
}
public int ProgramId
{
//automatically set the last sw that used the app
get; set;
}
public DateTime LastUpdate { get; set; } = DateTime.Now;
//FKs
//Access to ItemMaster
[Display(Name = "Item")]
public int ItemMasterId { get; set; }
public ItemMaster ItemMaster { get; set; }
//Access to Company
[Display(Name = "Company")]
public int CompanyId { get; set; }
public Company Company { get; set; }
//Access to LedgerType
[Display(Name = "Scenario")]
public int LedgerTypeId { get; set; }
public LedgerType LedgerType { get; set; }
//Access to Customer
[Display(Name = "Customer")]
public int CustomerId { get; set; }
public Customer Customer { get; set; }
}
}
And here is the ViewModel:
namespace SalesBudget.Models.ViewModels
{
public class BudgetViewModel
{
public FBudget FBudget { get; set; }
public IEnumerable<FBudget> RecordsList { get; set; }
public IEnumerable<SelectListItem> ItemNumberList { get; set; }
public IEnumerable<SelectListItem> ItemDescriptionList { get; set; }
public IEnumerable<SelectListItem> PharmaFormList { get; set; }
public IEnumerable<SelectListItem> ProductGroupList { get; set; }
public IEnumerable<SelectListItem> CompanyList { get; set; }
public IEnumerable<SelectListItem> LedgerTypeList { get; set; }
public IEnumerable<SelectListItem> LedgerScenarioList { get; set; }
public IEnumerable<SelectListItem> CustomerList { get; set; }
public IEnumerable<SelectListItem> LicensingAreaList { get; set; }
public IEnumerable<SelectListItem> YearsList { get; set; }
public IEnumerable<SelectListItem> CurrencyList { get; set; }
}
}
RESOLVED
I forgot to add hidden input fields in the view in order to retrieve the values that I needed:
<div class="col-12">
#if (Model.FBudget.BudgetId != 0)
{
<input type="hidden" asp-for="FBudget.BudgetId" />
<input type="hidden" asp-for="FBudget.Quantity" />
<input type="hidden" asp-for="FBudget.UnitPrice" />
<input type="hidden" asp-for="FBudget.TotalAmount" />
title = "Edit Month details";
}
<br />
</div>
So now when the form is submitted so are the values captured with hidden fields.
Related
Controller
public async Task<IActionResult> Create(IFormFile? StaffPhoto, CollectionViewModel collectionModel)
{
if (StaffPhoto != null){...} // issue is StaffPhoto value is null
}
View Model
namespace Website.Models
{
public class CollectionViewModel
{
public Staff staff { get; set; }
public Contact contact { get; set; }
}
}
Entity Model
public class Staff
{
public int StaffId { get; set; }
[DisplayName("First Name")]
[Required]
public string StaffFirstName { get; set; }
[DisplayName("Last Name")]
[Required]
public string StaffLastName { get; set; }
[DisplayName("Photo")]
public string? StaffPhoto { get; set; }
}
View
#model CollectionViewModel
<form asp-action="Create" enctype="multipart/form-data" method="post" class="row g-3 mt-0">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="col">
<label asp-for="staff.StaffFirstName" class="form-label"></label>
<input asp-for="staff.StaffFirstName" class="form-control" />
<span asp-validation-for="staff.StaffFirstName" class="text-danger"></span>
</div>
<div class="col">
<label asp-for="staff.StaffLastName" class="form-label"></label>
<input asp-for="staff.StaffLastName" class="form-control" />
<span asp-validation-for="staff.StaffLastName" class="text-danger"></span>
</div>
<div class="col-md-3">
<label asp-for="staff.StaffPhoto" class="form-label"></label>
<input asp-for="staff.StaffPhoto" type="file" accept="image/*" class="form-control" />
<span asp-validation-for="staff.StaffPhoto" class="text-danger"></span>
#{if (ViewBag.fileUploadErrorMessage != null)
{
<span class="text-danger">#ViewBag.fileUploadErrorMessage</span>
}
}
</div>
<div class="col">
<input type="submit" value="Create" class="btn btn-primary" />
<a asp-action="Create" class="btn btn-secondary">Reset All</a>
</div>
</form>
You should add IFormFile in model.
public class CollectionViewModel
{
public Staff staff { get; set; }
public IFormFile StaffPhoto { get; set; }
public Contact contact { get; set; }
}
set StaffPhoto to asp-for in view.
<input asp-for="StaffPhoto" type="file" accept="image/*" class="form-control" />
I have a form that adds a branch, the form has a drop down to select the company name.
I created a viewModel that has the SelectListItem of the companies and the Branch Model
When submit a form, modelState.IsValid equals to false.
reason for that is because CompaniesList is required.
any idea why is it required? how can i overcome this?
Branch model:
public class Branch
{
public int Id { get; set; }
public int CompanyId { get; set; }
[MaxLength(50)]
public string? City { get; set; }
[MaxLength(50)]
public string? BranchName { get; set; }
public DateTime CreatedAt { get; set; }
[MaxLength(100)]
public string? CreatedBy { get; set; }
}
ViewModel:
public class BranchVM
{
public Branch branch { get; set; }
[AllowNull]
public IEnumerable<SelectListItem> CompaniesList { get; set; }
}
Create.cshtml:
#model Click2Lock.Models.BranchVM
<form method="post" enctype="multipart/form-data">
<div class="border p-3 mt-4">
<div class="row pb-2">
<h2 class="text-primary">Create Branch</h2>
<hr/>
</div>
<div class="col-8">
<label asp-for="branch.BranchName">Branch Name</label>
<input asp-for="branch.BranchName" class="form-control"/>
<span asp-validation-for="branch.BranchName" class="text-danger"></span>
</div>
<div class="col-8">
<label asp-for="branch.City">City</label>
<input asp-for="branch.City" class="form-control"/>
<span asp-validation-for="branch.City" class="text-danger"></span>
</div>
<div class="col-8 pb-4">
<div class="form-group row">
<div class="col-4">
<label asp-for="branch.CompanyId">Company</label>
</div>
<div class="col-8">
#Html.DropDownListFor(m => m.branch.CompanyId, Model.CompaniesList , "Select Order",
new { #class = "form-control" })
<span asp-validation-for="branch.CompanyId" class="text-danger"></span>
</div>
</div>
</div>
<div class="col-8">
<input type="hidden" asp-for="branch.CreatedAt" class="form-control" value="#DateTime.Now" />
</div>
<div class="col-8">
<input type="hidden" asp-for="branch.CreatedBy" class="form-control" value=#ViewBag.userName />
</div>
<button type="submit" class="btn btn-primary" style="width:200px">Add New Branch</button>
<a asp-controller="Company" asp-action="Index" class="btn btn-secondary" style="width:150px">
Back To List
</a>
</div>
</form>
create on Controller :
public IActionResult Create()
{
ViewBag.userName = (_unitOfWork.ApplicationUser.GetAll().
Where(q => q.UserName == User.Identity.Name).Select(q => q.FullName)).FirstOrDefault();
BranchVM branchVM = new BranchVM()
{
branch = new Branch(),
CompaniesList = _unitOfWork.Company.GetAll().OrderBy(a=>a.CompanyName).
Select(i => new SelectListItem
{
Text = i.CompanyName,
Value = i.Id.ToString()
})
};
return View(branchVM);
}
//POST
[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult Create(BranchVM branchVM)
{
ViewBag.msgCreate = 0;
ViewBag.msgGeneralException = 0;
if (ModelState.IsValid)
{
try
{
_unitOfWork.Branch.Add(branchVM.branch);
_unitOfWork.Save();
ViewBag.msgCreate = 1;
return View(branchVM);
}
catch (Exception ex)
{
ViewBag.msgGeneralException = 1;
return View(branchVM);
}
}
ViewBag.msgGeneralException = 1;
return View(branchVM);
}
One technique is to make it nullable:
public IEnumerable<SelectListItem>? CompaniesList { get; set; }
I am trying to validate specific fields from my model before the form is submitted. It works but message doesn't show, this is because name attributes doesn't match.
This is my model:
public class TaskList
{
[Key]
public int Id { get; set; }
[MaxLength(200, ErrorMessage = "Subject field can't have more than 250 characters.")]
[Required(ErrorMessage = "Subject field cannot be empty.")]
[Column(TypeName = "nvarchar")]
public string Subject { get; set; }
[MaxLength(1000, ErrorMessage = "Details field can't have more than 1000 characters.")]
[Column(TypeName = "nvarchar")]
public string Details { get; set; }
[Required(ErrorMessage = "Please select a module.")]
public TaskLabels Label { get; set; }
[Required]
[Column(TypeName = "date")]
public DateTime Created { get; set; }
[Column(TypeName = "date")]
public DateTime? DueDate { get; set; }
[Column(TypeName = "date")]
public DateTime? Completed { get; set; }
}
This is controller action:
[HttpPost]
public IActionResult TaskList(TaskList newTask)
{
_ticketRepo.AddTask(newTask);
return RedirectToAction("TaskList");
}
This is my viewmodel:
public class TaskListViewModel
{
public TaskList ToDo { get; set; }
public IEnumerable<TaskList> TasksList { get; set; }
}
And this is my form:
<div class="modal fade" id="modal-add">
<div class="modal-dialog modal-lg">
<form class="form-horizontal" asp-controller="home" asp-action="TaskList" method="post">
<div class="modal-content">
<div class="modal-header bg-success">
<h4 class="modal-title">Add New To Do Item</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="card-body">
<div class="form-group row">
<label asp-for="ToDo.Subject" class="col-sm-2 col-form-label">Subject</label>
<div class="col-sm-10">
<input type="text" asp-for="ToDo.Subject" name="Subject" class="form-control" placeholder="Subject">
<span asp-validation-for="#Model.ToDo.Subject" class="text-danger"></span>
</div>
</div>
<div class="form-group row">
<label asp-for="ToDo.Details" class="col-sm-2 col-form-label">Details</label>
<div class="col-sm-10">
<textarea asp-for="ToDo.Details" name="Details" class="form-control" placeholder="Provide some details about the task."></textarea>
<span asp-validation-for="ToDo.Details" class="text-danger"></span>
</div>
</div>
<div class="form-group row">
<label asp-for="ToDo.Label" class="col-sm-2 col-form-label">Module</label>
<div class="col-sm-10">
<select name="ToDo.Label" asp-for="Label" asp-items="Html.GetEnumSelectList<TaskLabels>()" class="form-control select2 select2-danger" data-dropdown-css-class="select2-danger" style="width: 100%;">
<option value="" selected="selected">Please select one</option>
</select>
<span asp-validation-for="ToDo.Label" class="text-danger"></span>
</div>
</div>
<div class="form-group row">
<label asp-for="ToDo.DueDate" class="col-sm-2 col-form-label">Date:</label>
<div class="col-sm-10 input-group date" id="duedate" data-target-input="nearest">
<input type="text" name="DueDate" asp-for="ToDo.DueDate" class="form-control datetimepicker-input" data-target="#duedate" />
<div class="input-group-append" data-target="#duedate" data-toggle="datetimepicker">
<div class="input-group-text"><i class="fa fa-calendar"></i></div>
</div>
</div>
</div>
<div asp-validation-summary="All" class="text-danger"></div>
</div>
<!-- /.card-body -->
</div>
<div class="modal-footer justify-content-between">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Save changes</button>
</div>
</div>
<!-- /.modal-content -->
</form>
</div>
<!-- /.modal-dialog -->
<script src="~/lib/jquery-validation/dist/jquery.validate.min.js"></script><script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"></script>
In my form, if I remove name attribute from input fields, validation works, validation messages are shown but model binding doesn't work and I get null exception error for my properties. What am I doing wrong?
Of course I had to instantiate viewmodel in my controller action! When I did that and removed all name attributes from input fields in my view, everything worked just fine!
[HttpPost]
public IActionResult TaskList(TaskListViewModel model)
{
if (ModelState.IsValid)
{
TaskList taskList = new TaskList
{
Created = DateTime.Now.Date,
Subject = model.ToDo.Subject,
Details = model.ToDo.Details,
DueDate = model.ToDo.DueDate,
Label = model.ToDo.Label
};
_ticketRepo.AddTask(taskList);
return RedirectToAction("TaskList");
}
else
{
return View();
}
}
When in view mode, I try to fill in and get the date, it always turns out to be empty, but for example, the string field is filled in. And if I don't use the ViewModel, but only the Booking model, the date is filled in. I would like the date to be filled in with the viewmodel as well...
Controller:
public async Task<IActionResult> CheckOut3(CheckoutModel broom)
{
if (ModelState.IsValid)
{
_context.Add(broom);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
return View(broom);
}
Model:
public class Booking
{
public int Id { get; set; }
public Room Room { get; set; }
public string LastName { get; set; }
public string FirstName { get; set; }
[DisplayFormat(ApplyFormatInEditMode =true, DataFormatString = "{0:yyyy-MM-dd}")]
public DateTime? CheckInDate{ get; set; }
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:yyyy-MM-dd}")]
public DateTime? CheckOutDate { get; set; }
}
ViewModel:
public class CheckoutModel
{
public Booking booking {get; set;}
public Room room { get; set; }
}
View:
<form asp-action="Checkout3">
<div class="row">
<!--Grid column-->
<div class="col-lg-6 col-md-12 mb-4">
<label asp-for="booking.CheckInDate">CheckIn</label>
<input asp-for="booking.CheckInDate" class="form-control" type="datetime-local" name="CheckInDate" />
<span asp-validation-for="booking.CheckInDate" class="text-danger"></span>
</div>
<!--Grid column-->
<div class="col-lg-6 col-md-6 mb-4">
<label asp-for="booking.CheckOutDate">CheckOut</label>
<input asp-for="booking.CheckOutDate" class="form-control" type="date" name="CheckOutDate" />
<span asp-validation-for="booking.CheckOutDate" class="text-danger"></span>
</div>
</div>
<div class="form-group">
<input type="submit" value="Checkout" class="btn btn-primary" />
</div>
</form>
The problem is, you're posting CheckInDate and CheckOutDate in the html form, while it should be booking.CheckInDate and booking.CheckOutDate. Remove the name in your view, so name will be set with the value provided in asp-for.
<!--Grid column-->
<div class="col-lg-6 col-md-12 mb-4">
<label asp-for="booking.CheckInDate">CheckIn</label>
<input asp-for="booking.CheckInDate" class="form-control" type="datetime-local" />
<span asp-validation-for="booking.CheckInDate" class="text-danger"></span>
</div>
<!--Grid column-->
<div class="col-lg-6 col-md-6 mb-4">
<label asp-for="booking.CheckOutDate">CheckOut</label>
<input asp-for="booking.CheckOutDate" class="form-control" type="date" />
<span asp-validation-for="booking.CheckOutDate" class="text-danger"></span>
</div>
Have this class:
public class ClientViewModel
{
public long PKID { get; set; }
[Required]
public string Name { get; set; }
public string Unit { get; set; }
public string StreetNumber { get; set; }
public string Street { get; set; }
public string Suburb { get; set; }
public string State { get; set; }
public string PostCode { get; set; }
public string Country { get; set; }
public string DT_RowId { get; set; }
public double Longitude { get; set; }
public double Latitude { get; set; }
public bool IsActive { get; set; }
}
And this code for razor view:
<form method="post" asp-controller="Clients" asp-action="Edit">
<input asp-for="PKID" type="hidden" />
<div class="portlet-body">
<div class="row">
<div class="form-group col-md-2">
<label asp-for="Name">Name:</label>
<input class="form-control input-sm" type="text" placeholder="Name" asp-for="Name">
<span class="help-block has-error" asp-validation-for="Name"></span>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="row physical-row default-row">
<div class="col-md-2">
<label class="control-label">Unit</label>
#Html.TextBoxFor(model => model.Unit, new {placeholder = "Unit", id = "physicalLocationUnit", #class = "form-control input-sm"})
</div>
<div class="col-md-4">
<label class="control-label">Street</label>
#Html.TextBoxFor(model => model.Street, new {placeholder = "PhysicalAddress", id = "physicalLocation", onfocus = "physicalinitialize()", #class = "form-control input-sm"})
</div>
<div class="col-md-2 postcode-box">
<label class="control-label">Post Code</label>
<div>
<input type="text"
tabindex="-1"
class="form-control input-sm" />
</div>
</div>
<div class="col-md-2 lattitude-box">
<label class="control-label" asp-for="Latitude">Latitude</label>
<div>
<input type="text"
tabindex="-1"
class="form-control input-sm" asp-for="Latitude" />
</div>
</div>
<div class="col-md-2 longitude-box">
<label class="control-label" asp-for="Longitude">Longitude</label>
<div>
<input type="text"
tabindex="-1"
class="form-control input-sm" asp-for="Longitude" />
</div>
</div>
</div>
</div>
<div class="form-actions">
<div class="col-md-offset-6 col-md-6">
<button type="submit" class="btn green">Save</button>
<a asp-controller="Clients" asp-action="WorkManage" asp-route-id="#Model.PKID" class="btn green">Add Work</a>
</div>
</div>
</div>
</div>
</form>
In Longitude and Latitude has value for example 1.3 and 2.45 but when i try to call controller method i have just 0 value in this variables. Where i was wrong?
Cheers!
The reason it is not working with a period, is that the default CultureInfo on your server accepts only commas as decimal separators.
You might want to try setting the default culture to one that expects periods as decimal separators.
You could do that in your startup.cs, like this :
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, FinOsDbContext context)
{
app.UseRequestLocalization();
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("*insert culture*");
CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo("*insert culture*");
}
If you always intend to use a period as decimal separator, regardless of the culture's default, you could specify which decimal separator the culture should use like so :
System.Globalization.CultureInfo customCulture = new CultureInfo("*insert culture*");
customCulture.NumberFormat.NumberDecimalSeparator = ".";
CultureInfo.DefaultThreadCurrentCulture = customCulture;
CultureInfo.DefaultThreadCurrentUICulture = cultureInfo;