Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 如何使用MVC4从Viewbag呈现HTML_Asp.net Mvc_Asp.net Mvc 4_Viewbag - Fatal编程技术网

Asp.net mvc 如何使用MVC4从Viewbag呈现HTML

Asp.net mvc 如何使用MVC4从Viewbag呈现HTML,asp.net-mvc,asp.net-mvc-4,viewbag,Asp.net Mvc,Asp.net Mvc 4,Viewbag,我需要使用ViewBag将表单元素传递到MVC4视图中。Viewbag是每个用户的一个或多个记录的列表。问题是什么都没有通过 控制器 // grab all records for user id 26000. var qry = db.users.Where(m => m.user_id == "26000").ToList(); foreach (var myBag in qry) { // place all the items in the Vi

我需要使用ViewBag将表单元素传递到MVC4视图中。Viewbag是每个用户的一个或多个记录的列表。问题是什么都没有通过

控制器

// grab all records for user id 26000.
    var qry = db.users.Where(m => m.user_id == "26000").ToList();
    foreach (var myBag in qry)
    { 
     // place all the items in the Viewbag.
    ViewBag.myItems = "<input type='text' name=@ViewBag.myBag value=@ViewBag.myBag>";
    } 
看法


控制器查询实际上应该在您的模型中

ViewBag.myItems = db.users.Where(m => m.user_id == "26000").ToList();
看法

ViewBag.myItems = db.users.Where(m => m.user_id == "26000").ToList();
@using (Html.BeginForm("Index", "Home"))
{
    foreach (var item in ViewBag.myItems)
    {
        <input type="text" name="@item.user_id" value="@item.user_name">
    }
    <input id='btnSubmit' type="submit" value='submit' /> 
}