Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.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/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
.net 如何嵌入仅在满足某些条件时才可显示的局部视图_.net_Asp.net Mvc_Razor_Asp.net Mvc 5_Asp.net Mvc Partialview - Fatal编程技术网

.net 如何嵌入仅在满足某些条件时才可显示的局部视图

.net 如何嵌入仅在满足某些条件时才可显示的局部视图,.net,asp.net-mvc,razor,asp.net-mvc-5,asp.net-mvc-partialview,.net,Asp.net Mvc,Razor,Asp.net Mvc 5,Asp.net Mvc Partialview,我有一个名为Posted的局部视图。我希望当用户在我的主视图上执行某些活动时(单击“提交”按钮),显示该部分视图 我的部分观点如下 @using WebApplication1.Models @{ ViewBag.Title = "Posted"; } <h2>Posted</h2> @foreach (Data d in ViewBag.Data) { <table class="table table-striped"> <t

我有一个名为Posted的局部视图。我希望当用户在我的主视图上执行某些活动时(单击“提交”按钮),显示该部分视图

我的部分观点如下

@using WebApplication1.Models
@{
   ViewBag.Title = "Posted";
 }

<h2>Posted</h2>

@foreach (Data d in ViewBag.Data)
{
  <table class="table table-striped">
    <tr>
        <td><img src="@d.b64" style="width:200px;height:100px" /></td>
        <td><span>@d.bio</span></td>
        <td>@d.url</td>
    </tr>
</table>

 }
下面是我在Posted Action方法中的代码

   public ActionResult Posted(int cat) {
        var v = from c in
                    done.s1
                where c.catid==cat
                select c;

        List<Models.Data> data = new List<Models.Data>();
        foreach(s1 s in v)
        {
            var img = Models.StringCipher.DecryptImage( s.us,"abc");
            var str = Convert.ToBase64String(img);
            str = "data:image/png;base64," + str;
            string bio1 = Models.StringCipher.Decrypt(s.bio, "abc");
            string url1 = Models.StringCipher.Decrypt(s.url, "abc");

            data.Add(new Models.Data() { us=null, b64=str,url=url1,bio=bio1 });
        }
        ViewBag.data = data;
        return View("Posted");
    }
public ActionResult发布(int cat){
var v=从c英寸开始
完成。s1
其中c.catid==cat
选择c;
列表数据=新列表();
foreach(s1s在v中)
{
var img=Models.StringCipher.DecryptImage(s.us,“abc”);
var str=Convert.ToBase64String(img);
str=“data:image/png;base64,”+str;
string bio1=Models.StringCipher.Decrypt(s.bio,“abc”);
字符串url1=Models.StringCipher.Decrypt(s.url,“abc”);
data.Add(newmodels.data(){us=null,b64=str,url=url1,bio=bio1});
}
ViewBag.data=数据;
返回视图(“已发布”);
}

当用户从下拉列表中选择cat并单击“提交”按钮时,会出现“已发布的”视图。

不清楚您的要求。您提交的POST方法中的代码是什么?您是返回视图还是重定向?为什么要使用
@foreach(ViewBag.Data中的数据d)
-如果
数据
,您将得到一个exception@StephenMuecke在索引视图中,我有表单和提交按钮,点击它将通过执行“返回视图(“已发布”)显示
Posted
View那么,在您的
索引
视图中显示部分内容的代码是什么?您是否为
ViewBag.Data
分配了一个值,以及在哪里?您需要在问题中提供更多上下文。
ViewBag.data
在控制器中,以及
ViewBag.data
在视图中:)停止使用
ViewBag
并使用视图models@StephenMuecke我的数据是一个集合,而不仅仅是一个对象,不清楚你在问什么。您提交的POST方法中的代码是什么?您是返回视图还是重定向?为什么要使用
@foreach(ViewBag.Data中的数据d)
-如果
数据
,您将得到一个exception@StephenMuecke在索引视图中,我有表单和提交按钮,点击它将通过执行“返回视图(“已发布”)显示
Posted
View那么,在您的
索引
视图中显示部分内容的代码是什么?您是否为
ViewBag.Data
分配了一个值,以及在哪里?您需要在问题中提供更多上下文。
ViewBag.data
在控制器中,以及
ViewBag.data
在视图中:)停止使用
ViewBag
并使用视图models@StephenMuecke我的数据是一个集合,而不仅仅是一个对象
   public ActionResult Posted(int cat) {
        var v = from c in
                    done.s1
                where c.catid==cat
                select c;

        List<Models.Data> data = new List<Models.Data>();
        foreach(s1 s in v)
        {
            var img = Models.StringCipher.DecryptImage( s.us,"abc");
            var str = Convert.ToBase64String(img);
            str = "data:image/png;base64," + str;
            string bio1 = Models.StringCipher.Decrypt(s.bio, "abc");
            string url1 = Models.StringCipher.Decrypt(s.url, "abc");

            data.Add(new Models.Data() { us=null, b64=str,url=url1,bio=bio1 });
        }
        ViewBag.data = data;
        return View("Posted");
    }