0

让我解释一下我的问题。

我开发了一个 mvc4 Web 应用程序来上传图像并使用自定义文件名将其保存在另一个位置。

我的视图页面中有一个文件上传控件和一个按钮。在这个视图中还有另一个部分视图呈现,它有一些文本框。当我使用文件上传控件上传图像并单击提交按钮时,它应该保存在给定的位置并且文件名应该是局部视图中文本框的输入值。

这是视图的代码

<div id="partial">
            @{Html.RenderPartial("WholeSaleUserDetail");}
            @using (Html.BeginForm("uploadFile", "WholeSaleTrade", FormMethod.Post, new { enctype = "multipart/form-data" }))
            {
                <table>
                    <tr>
                        <td>
                            <img id="blah" src="../../Images/no_image.jpg" alt="your image" height="200px" width="150px" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <input type="file" id="imgInp" name="imgInp" />
                        </td>
                        <td>
                            <input type="submit" value="Upload Me" id="uploadme" />
                        </td>
                    </tr>
                </table>
            }
        </div>

这是名为“WholeSaleUserDetail”的局部视图代码

@model PortalModels.WholeSaleModelUser
@using (Html.BeginForm())

{
   @Html.ValidationSummary(true)

<fieldset>
    <legend>WholeSaleModelUser</legend>
    <table>
        <tr>
            <td>
                <div class="editor-label">
                    @Html.LabelFor(model => model.Name)
                </div>
            </td>
            <td>
                <div class="editor-field">
                    @Html.TextBoxFor(model => model.Name)
                    @Html.ValidationMessageFor(model => model.Name)
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <div class="editor-label">
                    @Html.LabelFor(model => model.Contact)
                </div>
            </td>
            <td>
                <div class="editor-field">
                    @Html.TextBoxFor(model => model.Contact)
                    @Html.ValidationMessageFor(model => model.Contact)
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <div class="editor-label">
                    @Html.LabelFor(model => model.Email)
                </div>
            </td>
            <td>
                <div class="editor-field">
                    @Html.TextBoxFor(model => model.Email)
                    @Html.ValidationMessageFor(model => model.Email)
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <div class="editor-label">
                    @Html.LabelFor(model => model.Fax)
                </div>
            </td>
            <td>
                <div class="editor-field">
                    @Html.TextBoxFor(model => model.Fax)
                    @Html.ValidationMessageFor(model => model.Fax)
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <div class="editor-label">
                    @Html.LabelFor(model => model.Address)
                </div>
            </td>
            <td>
                <div class="editor-field">
                    @Html.TextBoxFor(model => model.Address)
                    @Html.ValidationMessageFor(model => model.Address)
                </div>
            </td>
        </tr>
    </table>
    <input type="Submit" id="" value="Edit" />
    <input type="Submit" id="" value="Delete" />
</fieldset>

}

这是控制器代码

[HttpPost]
    public ActionResult uploadFile(HttpPostedFileBase imgInp, string imageName) 
    {
        var fileSavePath = "";
        var uploadedFile = Request.Files[0];
        //fileName = Path.GetFileName(uploadedFile.FileName);
        fileSavePath = Server.MapPath("~/Img/" + imageName + ".jpg");
        uploadedFile.SaveAs(fileSavePath);

        return RedirectToAction("Index");
    }

我需要使用文件上传控件保存图像上传,名称应该是部分视图中文本框“名称”的值

但我无法将文本框值传递给控制器​​。如何实现?

请帮我在这里..

4

0 回答 0