0

当我按下按钮一次时,我想开始上传和保存。我知道要使用两个不同的按钮来处理两个功能,一个是上传,另一个是保存。有什么建议吗?此代码适用于两个按钮,每个按钮用于一个功能。那是代码。提前致谢。

@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")
}
4

1 回答 1

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" />
于 2013-05-28T07:57:53.657 回答