简体   繁体   中英

Add File Upload Control in asp.net mobile website?

Currently, I'm working on asp.net mobile website and I've to implement one functionality related to upload file in mobile website.

I'm using asp:upload Control but, It's not working in mobile website.

I have been searching in google for this issue since last week, But I can't find any relative source or blog.

Can anyone help me on this topic?

In view:

@using (Html.BeginForm("Index", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    <input type="file" name="file" />
    <input type="submit" value="OK" />
}

In Control:

[HttpPost]
        public ActionResult Index(HttpPostedFileBase file)
        {
            // Verify that the user selected a file
            if (file != null && file.ContentLength > 0)
            {
                // extract only the fielname
                var fileName = Path.GetFileName(file.FileName);
                // store the file inside ~/App_Data/uploads folder
                var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName);
                file.SaveAs(path);
            }
            // redirect back to the index action to show the form once again

            return RedirectToAction("Index");
        }

and remove the jquerymobile script from your page. Like in MVC4

@Scripts.Render("~/bundles/jquery", "~/bundles/jquerymobile") 

Remove this line, it's the source of the conflict.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM