如何在索引页面上返回这两个语句? [英] how to return this both statement on index page?

查看:68
本文介绍了如何在索引页面上返回这两个语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  public  ActionResult Index()
{
var file = Server.MapPath( 〜/ app_data / ipl.mp3);
return 文件(文件, audio / MP3\" );
return 查看(db.Notes.ToList());

}







如何更正此代码我必须同时返回页面加载语句,但它单独工作?

解决方案

我会在模型或视图包中传递对服务器上文件的引用



然后在视图中,在页面就绪事件中启动文件下载或者你想用它做什么。



例如

  public  ActionResult Index()
{
viewbag.filepath = Server.MapPath ( 〜/ app_data / ipl.mp3);
return 查看(db.Notes.ToList());

}





在视图中,您可以通过viewbag.filepath访问文件路径


public ActionResult Index()
       {
           var file = Server.MapPath("~/app_data/ipl.mp3");
           return File(file, "audio/mp3");
           return View(db.Notes.ToList());

       }




How to correct this code i have to return both statement on page load but it works individually?

解决方案

I would pass a reference to the file on the server in the model or viewbag

Then in the view, on the page ready event intiate the file download or whatever you are trying to do with it.

e.g.

public ActionResult Index()
       {
           viewbag.filepath = Server.MapPath("~/app_data/ipl.mp3");
           return View(db.Notes.ToList());

       }



in the view, you can then access the file path via the viewbag.filepath


这篇关于如何在索引页面上返回这两个语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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