0

I am working on Angular js MVC application. I need a local file path which user selects from his/her local file system. I know I can't get full file path in Javascript so I tried to get this using c#. So I added 1 chtml page with input box & controller to get the file Here is chtml code

<div class="col-md-9">
    @using (Html.BeginForm("GetFile", "File", FormMethod.Post, new { enctype = "multipart/form-data" })) {
        <input type="file" name="file" />
        <input type="submit" name="Submit" id="Submit" value="Upload" />
    }
</div>

In controller I wrote

 [HttpPost]
    public ActionResult GetFile(HttpPostedFileBase file) {
        if (file != null) {
            string justFileName = Path.GetFullPath(file.FileName);
        }
        return justFileName;
    }
}

Also I have added the route in routeprovider

.when('/File', {
    templateUrl: 'File/Index'
})

I can easily access this page via URL. But now I need to call this page in an AngularJS modal popup or to show in a page itself on button click. I'm a bit newer to AngularJS. I tried with ng-view but it won't work. Please let me know If I am in a wrong direction? Is there any way to call chtml inside HTML? The question may be misleading but It is my final moto.

lin
  • 17,956
  • 4
  • 59
  • 83
Rohi_Dev_1.0
  • 372
  • 1
  • 2
  • 19
  • If you'd like to do this in angular, get rid of the cshtml and go straight html. There are several suggestions for doing a file upload in this post http://stackoverflow.com/questions/18571001/file-upload-using-angularjs or look at this example https://code.msdn.microsoft.com/AngularJS-with-Web-API-22f62a6e – jbrown Apr 03 '17 at 12:36
  • @jbrown I I don't want to upload file I need a file path. – Rohi_Dev_1.0 Apr 03 '17 at 12:43

1 Answers1

0

You need to add following line in your angular js controller when you want popup to be shown.

ngDialog.open({template: 'File/Index'});

Reference: http://ngmodules.org/modules/ngDialog

Muhammad Ramzan
  • 342
  • 3
  • 16