Microsoft Visual Web Developer 2010 Expressの.web部分にASP.NETプロジェクトを作成し、Silverlightプロジェクトを含めました。音楽ブログのようなものを作成しました。「パス」の値をSilverlightに渡したいと思います。ユーザーがファイルをアップロードすると、トラックがSilverlightアプリで再生されます。
たとえば、データベースにPostsというテーブルと、ファイルのパスが格納されているTrackというPostsから派生した別のテーブルを作成しました。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);
}
ASP.NETページに埋め込まれているSilverlightアプリでトラックを再生できるように、Silverlightのプレーヤーにパスを渡すにはどうすればよいですか?