我的创建操作未触及断点。我修复了我的Visual Studio(2015)并确保我处于调试模式。我清理并重建了几次。我将源代码移动到VS的新实例。 PDB文件存在。 除了创建一个动作/方法之外,我可以点击其他动作/方法的断点,我使用 httppostedfilebase 来上传图像和歌曲。
当我创建错误时,如下所示:
输入不是有效的Base-64字符串,因为它包含非基本64个字符,两个以上的填充字符或填充字符中的非法字符。
这是我的控制器动作:
public async Task<ActionResult> CreateSong([Bind(Include = "SongID,Title,ReleaseDate,Genre,Price,Rating,Poster,PosterFilePath,FileType,Audio,AudioFilePath,Likes,DisLikes,Faves,Reposts")] Song song, HttpPostedFileBase image, HttpPostedFileBase audio)
{
if (ModelState.IsValid)
{
if (image != null && image.ContentLength > 0)
{
song.Poster = new byte[image.ContentLength];
song.Likes = 0;
song.DisLikes = 0;
song.Faves = 0;
song.Reposts = 0;
image.InputStream.Read(song.Poster, 0, image.ContentLength);
var imgName = Path.GetFileName(image.FileName);
song.PosterFilePath = "../Uploads/Song/" + imgName;
image.SaveAs(Path.Combine(Server.MapPath("~/Uploads/thumbnails/"), imgName));
}
SongLike songLike = new SongLike();
songLike.Liked = false;
songLike.LikedDate = DateTime.Today;
songLike.SongLikeId = song.SongID;
if (audio != null && audio.ContentLength > 0)
{
var audName = Path.GetFileNameWithoutExtension(audio.FileName);
var audExt = Path.GetExtension(audio.FileName);
song.FileType = audExt;
string path = "../Uploads/songs/" + audName + audExt;
song.AudioFilePath = path;
audio.SaveAs(Path.Combine(Server.MapPath("~/Uploads/songs/"), audName + audExt));
string output = Server.MapPath("~/Uploads/songs/" + audName + audExt);
}
db.Songs.Add(song);
db.SongLikes.Add(songLike);
await db.SaveChangesAsync();
return RedirectToAction("Index");
}
ViewBag.CategoryID = new SelectList(db.Categories, "ID", "Name", song.CategoryID);
return View(song);
}