打开对话框并在MVC中获取文件路径

时间:2021-10-13 09:58:43

am beginner to mvc. I have a slightly unusual situation.i have converting my windows project to MVC web application using razor.

我是mvc的初学者。我有一个稍微不寻常的情况。我已经使用razor将我的Windows项目转换为MVC Web应用程序。

What i needed is Click the button and open dialog box and my to Get file path from dialog box to textbox Like C:\user\Accentra\Desktop\durai

我需要的是单击按钮并打开对话框,然后从我的“获取文件路径”对话框到文本框,如C:\ user \ Accentra \ Desktop \ durai

thanks advance

谢谢提前

Durai

Durai

1 个解决方案

#1


1  

Not sure what you mean here. are you referring to a file upload, so the user presses a button, selects the file and then save it to the server? if so...

不确定你的意思。你指的是文件上传,所以用户按下按钮,选择文件,然后将其保存到服务器?如果是这样...

you can have a say, file upload control when the user can then upload a file - on POST, the value gets posted to you to which then you do what you need to when saving to the server.

当用户可以上传文件时,您可以拥有一个说文件上传控件 - 在POST时,该值会发布给您,然后您在保存到服务器时执行所需操作。

example:

例:

public ActionResult Index(HttpPostedFileBase file) {

  if (file.ContentLength > 0) {
    var fileName = Path.GetFileName(file.FileName);
    var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName);
    file.SaveAs(path);
  }

  return RedirectToAction("Index");
}

#1


1  

Not sure what you mean here. are you referring to a file upload, so the user presses a button, selects the file and then save it to the server? if so...

不确定你的意思。你指的是文件上传,所以用户按下按钮,选择文件,然后将其保存到服务器?如果是这样...

you can have a say, file upload control when the user can then upload a file - on POST, the value gets posted to you to which then you do what you need to when saving to the server.

当用户可以上传文件时,您可以拥有一个说文件上传控件 - 在POST时,该值会发布给您,然后您在保存到服务器时执行所需操作。

example:

例:

public ActionResult Index(HttpPostedFileBase file) {

  if (file.ContentLength > 0) {
    var fileName = Path.GetFileName(file.FileName);
    var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName);
    file.SaveAs(path);
  }

  return RedirectToAction("Index");
}