学习MVC4/C#。只是简单地尝试将电影列表发布回控制器,但它是空的。我是否正确定义了类?
我有以下型号
namespace videostore.Models
{
public class MovieSummary
{
public List<Movie> Movies { get; set; }
}
public class Movie
{
public string name { get; set; }
}
}
跟随控制器
[HttpPost]
public ActionResult SaveMovies(MovieSummary movieList)
{
}
和以下html
<script type="text/javascript">
$(document).ready(function () {
$("form").submit(function (e) {
e.preventDefault();
$.post('/SaveMovies', $('form').serialize(), function (data) {
});
});
});
</script>
<form>
<input type="hidden" name="movie" value="Man of Steel" />
<input type="hidden" name="movie" value="The Dark Knight" />
<input type="hidden" name="movie" value="Iron Man" />
<input type="submit" name="submit" value="submit" />
</form>