ASP.NET MVC APP Request.form дает нулевое значениеHtml

Программисты Html
Ответить
Anonymous
 ASP.NET MVC APP Request.form дает нулевое значение

Сообщение 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

Подробнее здесь: https://stackoverflow.com/questions/795 ... null-value
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Html»