Когда я пытаюсь преобразовать число, подобное 1.1, в двойное, я получаю исключение: «Входная строка была в неправильном формате». Я не знаю, почему это происходит, поскольку вводимые мной данные верны, а переменная, в которую я преобразую, является двойной. Ниже приведен код:
Метод создания контроллера:
[ValidateAntiForgeryToken]
public ActionResult Create(IFormCollection collection)
{
try
{
Riskanalysis riskanalysis = new Riskanalysis()
{
dateCreation = Convert.ToDateTime(collection["dateCreation"]),
userId = collection["userId"],
categoryId = Convert.ToInt32(collection["categoryId"]),
zoneId = Convert.ToInt32(collection["zoneId"]),
equipmentId = Convert.ToInt32(collection["equipmentId"]),
taskId = Convert.ToInt32(collection["taskId"]),
activity = collection["activity"],
action = collection["action"],
descriptionPotentialRisk = collection["descriptionPotentialRisk"],
dangerId = Convert.ToInt32(collection["dangerId"]),
consequenceId = Convert.ToInt32(collection["consequenceId"]),
dangerousEnergiesId = Convert.ToInt32(collection["dangerousEnergiesId"]),
preventionMeasures = collection["preventionMeasures"],
safetyProcedures = collection["safetyProcedures"],
preSeriousness = Convert.ToDouble(collection["preSeriousness"]),
preProbability = Convert.ToDouble(collection["preProbability"]),
preExposure = Convert.ToDouble(collection["preExposure"]),
preRiskDegree = Convert.ToDouble(collection["preRiskDegree"]),
preRiskCategory = Convert.ToDouble(collection["preRiskCategory"]),
};
DanoneRiskanalysisManager rm = new DanoneRiskanalysisManager();
rm.InsertRiskanalysis(riskanalysis);
return RedirectToAction(nameof(Create));
}
catch (Exception e)
{
return View();
}
}
Поля ввода:
<div class="form-group">
<label asp-for="preSeriousness" class="control-label">Pre seriousness:</label>
<input asp-for="preSeriousness" class="form-control" type="text" required/>
<span asp-validation-for="preSeriousness" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="preProbability" class="control-label">Pre probability:</label>
<input asp-for="preProbability" class="form-control" type="text" required/>
<span asp-validation-for="preProbability" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="preExposure" class="control-label">Pre exposure:</label>
<input asp-for="preExposure" class="form-control" type="text" required/>
<span asp-validation-for="preExposure" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="preRiskDegree" class="control-label">Pre risk degree:</label>
<input asp-for="preRiskDegree" class="form-control" type="text" required/>
<span asp-validation-for="preRiskDegree" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="preRiskCategory" class="control-label">Pre risk category:</label>
<input asp-for="preRiskCategory" class="form-control" type="text" required/>
<span asp-validation-for="preRiskCategory" class="text-danger"></span>
</div>
Кто-нибудь знает, что может быть причиной или где искать?
Спасибо уже!