Actually I want to send the image and the text in the textbox to the controller...
@using (Html.BeginForm("Upload", "Home", FormMethod.Post, new { enctype = "multipart/form-data" })) { @Html.Label("UserName:") <input type="text" id="txtImg" name="txtImg" /><br /><br /> @Html.Label("Upload:")<input type="file" name="image" /><br/> <div id="Preview"> Preview </div> <input class="btn btn-success btnUpload" type="submit" value="upload" /> } and I am trying to retrieve them in the controller in the below way:
public ActionResult Upload(HttpPostedFileBase image,string txtImg) but I am not getting the textbox value..Is anything wrong withe code?
I have my sample code like this.
Controller: public ActionResult Upload() { BlobStorageServices _blobstorageservice = new BlobStorageServices(); CloudBlobContainer container = _blobstorageservice.GetCloudBlobContainer(); List<string> blobs = new List<string>(); //List<BlobModel> models = BlobManager.getBlobs(); foreach (var blobItem in container.ListBlobs()) { blobs.Add(blobItem.Uri.ToString()); } return View(blobs); } [HttpPost] public ActionResult Upload(string txtImg,HttpPostedFileBase image) { if (image.ContentLength > 0) { BlobStorageServices _blobstorageservice = new BlobStorageServices(); CloudBlobContainer container = _blobstorageservice.GetCloudBlobContainer(); CloudBlockBlob blob = container.GetBlockBlobReference(image.FileName); //BlobManager.insertBlobUri(new BlobImage { Uri = blob.Uri.ToString() }); // string text = model.Name; BlobManager.insertBlobUri(new BlobModel {Name=txtImg,Uri=blob.Uri.ToString()}); blob.UploadFromStream(image.InputStream); } return RedirectToAction("Upload"); } View @using (Html.BeginForm("Upload", "Home", FormMethod.Post, new { enctype = "multipart/form-data" })) { @Html.Label("UserName:") <input type="text" id="txtImg" name="txtImg" /><br /><br /> @Html.Label("Upload:")<input type="file" name="image" id="upload"/><br/> <div id="Preview"> Preview<img id="blah" src="#" alt="your image" /> </div> <input class="btn btn-success btnUpload" type="submit" value="upload" /> } <table style="border:1"> @foreach (var item in Model) { <tr style="border:1"> <td><img src="@item" alt="image" class="img-responsive" width="100" height="100" /></td> <td><button class="btn btn-primary Delete" id="@item" onclick="deleteImage('@item');">Delete</button></td> <td><a class="btn btn-primary Download" href="@item" target="_blank">Download Image</a></td> <td><button class="btn btn-primary Download" onclick="updateImage('@item');">UpdateImage</button></td> </tr> } I am sending the blobs directly into the view , that is the problem basically..How to use a model to insert text,bloburl,image?
Upload(string txtImg, HttpPostedFileBase image)?