当我按下按钮一次时,我想启动上传和保存。我知道要使用两个不同的按钮来处理两个功能,一个是上传,另一个是保存。有什么建议吗?此代码适用于一个功能的两个按钮。那是代码。提前谢谢。
@model MvcMovie.Models.Movie
@{
ViewBag.Title = "Create";
}
<h2>Create</h2>
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>Movie</legend>
<div class="editor-label">
@Html.LabelFor(model => model.Title)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Title)
@Html.ValidationMessageFor(model => model.Title)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.ReleaseDate)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.ReleaseDate)
@Html.ValidationMessageFor(model => model.ReleaseDate)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Genre)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Genre)
@Html.ValidationMessageFor(model => model.Genre)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Price)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Price)
@Html.ValidationMessageFor(model => model.Price)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Rating)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Rating)
@Html.ValidationMessageFor(model => model.Rating)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.ImageUrl)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.ImageUrl)
@Html.ValidationMessageFor(model => model.ImageUrl)
</div>
<input type="submit" value="Create" />
</fieldset>
<img src="~/Content/Images/Full/i1.JPG" alt="Sample Image" width="300px" height="200px" />
<!--proba-->
}
@using (Html.BeginForm("Upload", "Movies", FormMethod.Post, new { enctype="multipart/form-data" }))
{
<input name="ImageUploaded" type="file">
<input type="submit" value="Upload"/>
}
<!--/proba-->
@Html.ActionLink("Back to List", "Index")
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
答案 0 :(得分:1)
您可以上传并保存在控制器中。否则你应该使用JQuery与Ajax结合这两者。以下是关于如何链接ajax调用的一点建议。
@using(Ajax.BeginForm("uploadaction", "controller", new AjaxOptions()
{
OnSuccess = "$(input#save).click()"
})
{
<input type="submit" style="display:none;" id="upload" />
}
@using(Ajax.BeginForm("saveaction", "controller", new AjaxOptions()
{
OnSuccess = "route to new url"
})
{
<input type="submit" style="display:none;" id="save" />
}
<input type="button" onclick="$(input#upload).click()" value="Upload and save" />