我正在尝试使用MVC上传附件功能。 我实际上做上传/保存附件的方法是期待HttpPostedFileBase类型。
public virtual string Upload(HttpPostedFileBase fileName) { //Code to upload/save attachment. }我的问题是“fileName”作为字符串从UI传递。 如何将字符串(文件路径名称)转换为我的Upload方法可以使用的内容。
提前致谢。
I am trying to do upload attachment functionality using MVC. My method that is actually doing the upload/save attachment is expecting a HttpPostedFileBase type.
public virtual string Upload(HttpPostedFileBase fileName) { //Code to upload/save attachment. }My problem is "fileName" is being passed from the UI as a string. How can I convert the string(file path name) into something my Upload method can work with.
Thanks in advance.
最满意答案
正如其他人所提到的,你的表单应该是这样的:
<form id="form_UploadFile" action="" method="post" enctype="multipart/form-data"> <label for="file">Filename:</label> <input type="file" name="file" id="file" /> </form>然后,正如你所提到的,你试图通过ajax发布,你可以使用jQuery serialize()来序列化formData,并将其推送到你的控制器。
$('#form_UploadFile').serialize();As mentioned by others, your form should look something like this:
<form id="form_UploadFile" action="" method="post" enctype="multipart/form-data"> <label for="file">Filename:</label> <input type="file" name="file" id="file" /> </form>Then as you mentioned you are trying to post via ajax, you can use jQuery serialize() to serialize the formData to be pushed to your controller.
$('#form_UploadFile').serialize();更多推荐
Upload,attachment,upload,string,方法,电脑培训,计算机培训,IT培训"/> <meta name=
发布评论