Asp.net通过上升事件来调用视图

时间:2017-04-18 15:26:08

标签: c# asp.net

我正在使用这个课程:

public class SteamGet
    {
        public delegate ActionResult ResultDone(List<Steam> List);
        public event ResultDone OnResultDone;

        public void Get()
        {
            Debug.Write("Result Received !");
            using (WebClient client = new WebClient())
            {
                string data = client.DownloadString("http://api.steampowered.com/ISteamApps/GetAppList/v0001/");
                JObject steamobject = JObject.Parse(data);
                var rslt = steamobject.SelectToken("applist").SelectToken("apps");
                var objd = JsonConvert.DeserializeObject<ObjectResult>(rslt.ToString());
                OnResultDone(objd.MyList);
            }
        }


    }

我的家庭控制器看起来像这样:

public class HomeController : Controller
{
    // GET: Home
    protected SteamGet Getter = new SteamGet();

    public ActionResult Index()
    {
        Getter.OnResultDone += Getter_OnResultDone;
        Task.Run(() => Getter.Get());
        return View();
    }

    private ActionResult Getter_OnResultDone(List<Models.Steam> List)
    {

        return View("ViewTest",List);
    }
}

因此你可以看到我调用Get()方法然后返回视图,当事件OnresultDone被提升时我想调用另一个视图或刷新主视图

我的家庭观点:

@using TemplateAspTest.Repository
@model List<TemplateAspTest.Models.Steam>

@{
    ViewBag.Title = "Home";
    Layout = "~/Views/Shared/_Main.cshtml";
}

<section id="intro" class="main">
    <span class="icon fa-diamond major"></span>
    <h2>Test one section ! </h2>
    <p>
        test done !
    </p>
    <ul class="actions">
        @{ 
            if (@Model == null)
            {
                <li>waiting ....</li>
            }
            else
            {
                <li>ViewBag.Message;</li>
                @Model[0].Name;
            }
        }
    </ul>
</section>

编辑: 我正在回归观看并等待一个事件被提出我希望在提出偶数时再调用另一个视图

0 个答案:

没有答案