Forum


HomeHomePremiumPremiumDevelopmentDevelopmentHow to implement upload file use Module RazorHow to implement upload file use Module Razor
Previous
 
Next
New Post
10/14/2014 7:39 PM
 

Now, i'm in project about portal using DotNetNuke.
This is my first time in DotNetNuke. I had watch your video about create module use razor, thats is so good for me, simple, direct to database without use DAL2, etc.
Now i'm done create razor module, create, update, delete from database.
But i'm still confuse how to upload file in razor module.
This is my script : (my reference from http://www.asp.net/web-pages/overview/data/working-with-files)

@using DotNetNuke.Common;
@using DotNetNuke.Entities.Users;
@using DotNetNuke.Web.UI.WebControls;
@using Microsoft.Web.Helpers;

@{
    var db = Database.Open("SiteSqlServer");
        var Alamat = Request.Form["iContent"];
        
        var fileName = "";
    if (IsPost) {
            var fileSavePath = "";
            var uploadedFile = Request.Files["uploadFile"];
            fileName = Path.GetFileName(uploadedFile.FileName);
            fileSavePath = Server.MapPath("~/App_Data/UploadedFiles/" + fileName);
            uploadedFile.SaveAs(fileSavePath);
            
            var insertQuery = "INSERT INTO TableName (Alamat, PathFIle) VALUES (@0, @1)";
            db.Execute(insertQuery, Alamat, fileSavePath);

            Response.Redirect(Url.NavigateToControl(""));
    }
}
<!DOCTYPE html>
<html>
    <head><title>FileUpload</title></head>
<body>
    <form id="myForm" method="post" enctype="multipart/form-data" action="">
                    <div class="form-group">
            <label class="col-lg-3 control-label">Alamat</label>
            <div class="col-lg-9">
              <input name="iAlamat" value="@Alamat" placeholder="Alamat" class="form-control" type="text">
            </div>
          </div>        

                    <div class="form-group">
              <label class="col-lg-3 control-label">Dokumen</label>
            <div class="col-lg-9"><input name="uploadFile" id="uploadFile" type="file"></div>
          </div>
          
          <div class="line line-dashed"></div>
          
          <div class="form-group">
            <input id="cmdSave" type="submit" value="Kirim Pengaduan" class="btn btn-primary" />
              <a href='@Url.NavigateToControl("")' id="cmdCancel" class="btn btn-danger">Batalkan</a>
          </div>
    </form>
</body>
</html>

i'm get blank page, when submit. whats wrong with that code?
what missing library. Please help me..
I need that solution, asap..

 
New Post
10/15/2014 4:38 AM
 

Hi Iwan,

I'm not 100% sure what is the problem here but I do see A problem: You have a FORM tag inside this script. This will cause a conflict with the FORM tag that DNN already has. I would try this script again without HTML , HEAD, BODY and FORM tags

Cheers,

Aderson

 
Previous
 
Next
HomeHomePremiumPremiumDevelopmentDevelopmentHow to implement upload file use Module RazorHow to implement upload file use Module Razor



Try FREE
30 days money back guaranteed