让我解释一下我的问题。
我开发了一个mvc4 Web应用程序来上传图像并将其保存在另一个带有自定义文件名的位置。
我的视图页面中有一个文件上传控件和一个按钮。此视图中还有另一个部分视图呈现,它有一些文本框。当我使用fileupload控件上传图像并单击它应该保存在给定位置的提交按钮,文件名应该是部分视图中文本框的输入值。
这是视图代码
<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");
}
我需要使用fileupload控件保存图像上传,名称应该是部分视图中文本框“名称”的值
但我无法将文本框值传递给controller.how来实现吗?
请帮助我...