public ActionResult AddFood()
{
if (Session["uid"] != null)
{
string email = Session["uid"].ToString();
var user = HomeController.Users.FirstOrDefault(x => x.Email == email);
var selectedFood = HomeController.Foods.FirstOrDefault(x => x.Name == Request.Form["selectedFood"]);
user.Foods.Add(selectedFood);
}
return RedirectToAction("Diet", "User");
}
< /code>
$(document).ready(function () {
$('#foodDropdown').select2({
placeholder: "Choose food",
allowClear: true
});
});
@Html.DropDownList("selectedFood", ViewBag.FoodList as SelectList, "Choose food", new { @class = "form-control", id = "foodDropdown" })
Add
< /code>
In html there's a DropDownList where you can select different food names and I want to use the selected name to get the whole food object but can't access to selected food name.
Request.Form["selectedFood"] returns null here, why?
I am guessing I should get the value in some different way when using @Html... but I don't know how
Подробнее здесь: https://stackoverflow.com/questions/795 ... null-value
ASP.NET MVC APP Request.form дает нулевое значение ⇐ Html
Программисты Html
-
Anonymous
1744414620
Anonymous
public ActionResult AddFood()
{
if (Session["uid"] != null)
{
string email = Session["uid"].ToString();
var user = HomeController.Users.FirstOrDefault(x => x.Email == email);
var selectedFood = HomeController.Foods.FirstOrDefault(x => x.Name == Request.Form["selectedFood"]);
user.Foods.Add(selectedFood);
}
return RedirectToAction("Diet", "User");
}
< /code>
$(document).ready(function () {
$('#foodDropdown').select2({
placeholder: "Choose food",
allowClear: true
});
});
@Html.DropDownList("selectedFood", ViewBag.FoodList as SelectList, "Choose food", new { @class = "form-control", id = "foodDropdown" })
Add
< /code>
In html there's a DropDownList where you can select different food names and I want to use the selected name to get the whole food object but can't access to selected food name.
Request.Form["selectedFood"] returns null here, why?
I am guessing I should get the value in some different way when using @Html... but I don't know how
Подробнее здесь: [url]https://stackoverflow.com/questions/79569844/asp-net-mvc-app-request-form-gives-null-value[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия