在MVC C#中的第二个观点没有显示 [英] nothing display in the second view in MVC c#

查看:167
本文介绍了在MVC C#中的第二个观点没有显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的网站,我是从XML在第一控制器的操作方法和显示的下拉列表中获取数据(HTML选择和选项)。当用户选择发送到下一个视图的控制器作为第一下拉列表中的项目,所选项目使用jQuery参数 $。交。我有保留断点,看看到底是怎么回事。数据trasfer是成功的,直到第二个观点。但是什么也不显示。我重视我的破发点的屏幕截图和codeS。

In my web site I'm getting data from xml in first controller action method and display as dropdown (html select and option).When a user selects an item in first dropdown, selected item sent to the next view's controller as a parameter using jquery $.post. I have keep breakpoints and see what is going on. Data trasfer is success until second view . But display nothing. I have attached screenshot of my break points and codes.

这是我的控制器。

public ActionResult First()
{
    //get the location data
    var Loc = getData("Location", "", "", "");
    List<FirstData> Ilc = new List<FirstData>();
    foreach(var val in Loc)
    {
       Ilc.Add(new Firstdata
       {
            Destination = val
       });
     }
     ViewBag.Loc = Ilc;
     return View();
}

这是我如何传递数据,从第一个以第二个动作控制器方法

this is how I pass data from first view to second action controller method

<script type:"text/javascript">
    $(document).ready(function() {
        $("#chk a").addCIass("btn btn-default");
        $("#chk a").click(function () {
            var url = '@Url.Action("Check","Cruise")';
            $.post(url, { LocNane: $("#desti").val() }, function (data) {
                //alert("succes");
            });
         });
     });
</script>

这是我的第二个控制器获取传递数据[我在这里做一个断点]

this is how my second controller gets pass data[I made a breakpoint here]

public ActionResult Check(string LocName)
{
    string d = LocNane;
    var Nan = getData('Location',"Name",d,"");
    List<Seconddata> nf = new List<Seconddata>();
    foreach (var val in Nam)
    {
        nf.Add(new Seconddata
        {
            Naneof = val
        });
    }
    ViewBag.Nn = nf;
 }

这是在破发点我的第二个观点和显示数据。

and this is my second view and display data in break point

<body>
    <div>
        @foreach( var item in @VieuBag.Nm)
        {
            <h3>one</h3>
        }
    </div>
</body>

我把@ item.Nameof的标题标签里面,但没有奏效。所以只是赤我放的。经过循环没什么display.what年代wrong.please帮助我后。

I put "@item.Nameof" inside the header tags , but it didn't work. so just to chek I put one. after go through the loop nothing display.what's the wrong.please help me with this.

推荐答案

这里的问题是$。员额不附加/插入任何元素返回的HTML的成功处理程序。你可以做这样的事情在成功处理程序,其中DIVID是元素的ID在页面上要显示返回的HTML。

The problem here is the success handler of $.post does not append/insert the returned html in any element. You can do something like this in success handler where divId is element Id in page where you want to show the returned html.

$("#divId").append(data);

这篇关于在MVC C#中的第二个观点没有显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆