我在.web部分的Microsoft Visual Web Developer 2010 Express中創建了一個ASP.NET項目,幷包含一個Silverlight項目。我創建了一個類似音樂博客的東西,我想將「路徑」值傳遞給Silverlight。用戶上傳文件,軌道將在Silverlight應用程序中播放。從ASP.NET傳遞值到Silverlight應用程序
我已經在數據庫中創建了一個名爲Posts的表格,另一個表格來自於名爲Track的帖子,其中存儲了文件的路徑。我也包括在我的Index.aspx文件:
<form id="form1" runat="server" style="height:50%">
<div id="silverlightControlHost">
<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="770" height="530">
<param name="source" value="ClientBin/MusicBlog.xap"/>
<param name="onError" value="onSilverlightError" />
<param name="background" value="white" />
<param name="minRuntimeVersion" value="3.0.40818.0" />
<param name="autoUpgrade" value="true" />
<a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40818.0" style="text-decoration:none">
<img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Holen Sie sich Microsoft Silverlight" style="border-style:none"/>
</a>
</object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe></div>
</form>
當創建一個帖子我打電話:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create(Posts model, HttpPostedFileBase file)
{
if (ModelState.IsValid)
{
if (file != null)
{
if (file.ContentLength > 0)
{
var fileName = Path.GetFileName(file.FileName);
var path = Path.Combine(Server.MapPath("~/Music"), fileName);
file.SaveAs(path);
Track track = new Track();
track.Path = path;
model.Track.Add(track);
DateTime today = DateTime.Today;
Posts post = new Posts();
/*post.Body = model.Body;
post.Created = model.Created;
post.Modified = model.Modified;
post.Title = model.Title;*/
model.Created.ToLocalTime();
postRepository.Create(model);
return RedirectToAction("Index");
}
else
{
ModelState.AddModelError("", "The given Path is invalid");
}
}
else
{
ModelState.AddModelError("", "The given Path is invalid");
}
}
return View(model);
}
如何我現在可以傳遞的路徑,在Silverlight播放器,這樣我就可以玩跟蹤,嵌入在ASP.NET頁面中的Silverlight應用程序中?
您知道Microsoft在桌面上甩了Silverlight嗎? – Rob