when i click submit button am getting everything including image path data in ajax.but in server side am not getting image path data renaming value am getting..
C#
@using (Html.BeginForm("AddDoctor", "Doctor", FormMethod.Post, new { id = "myForm", enctype = "multipart/form-data" })) { @Html.AntiForgeryToken() @Html.ValidationSummary(true) Doctor Registration
Doctor Experience
Doctor Education
Doctor Clinic Information
Tittle -- Select Tite -- Dr. Mr. Mrs. Miss. Ms. Prof. @Html.ValidationMessageFor(model => Model.DoctorRegistration.Tittle, null, new { @style = "color: red" })
Doctor Name @Html.TextBoxFor(model => Model.DoctorRegistration.DoctorName, new { @class = "form-control", @id = "txtDoctorName", placeholder = "Enter the Doctor Name" }) @Html.ValidationMessageFor(model => Model.DoctorRegistration.DoctorName, null, new { @style = "color: red" })
Doctor Code @Html.TextBoxFor(model => Model.DoctorRegistration.DoctorCode, new { @class = "form-control", @id = "txtDoctorCode", placeholder = "Enter the Doctor Code" })
Registration Number @Html.TextBoxFor(model => Model.DoctorRegistration.RegistrationNo, new { @class = "form-control", @id = "txtRegistrationNo", placeholder = "Doctor Registration Number" })
Gender
Male Female
@Html.ValidationMessageFor(model => Model.DoctorRegistration.Gender, null, new { @style = "color: red" })
Date Of Birth @*@Html.TextBoxFor(model => Model.DoctorRegistration.DocDOB, new { @class = "form-control", @id = "txtDocDOB", placeholder = "Enter the Doctor Code" })*@
@Html.ValidationMessageFor(model => Model.DoctorRegistration.DocDOB, null, new { @style = "color: red" })
Address Line 1 @Html.TextBoxFor(model => Model.DoctorRegistration.DocAddress1, new { @class = "form-control", @id = "txtDocAddress1", placeholder = "Enter the Address Line 1" }) @Html.ValidationMessageFor(model => Model.DoctorRegistration.DocAddress1, null, new { @style = "color: red" })
Address Line 2 @Html.TextBoxFor(model => Model.DoctorRegistration.DocAddress2, new { @class = "form-control", @id = "txtDocAddress2", placeholder = "Enter the Address Line 2" })
Country @Html.DropDownList("Country", null, "--- Select Country ---", new { @class = "select2-arrow" }) @Html.ValidationMessageFor(model => Model.DoctorRegistration.Country, null, new { @style = "color: red" })
State @Html.ValidationMessageFor(model => Model.DoctorRegistration.State, null, new { @style = "color: red" }) @Html.ValidationMessageFor(model => Model.DoctorRegistration.State, null, new { @style = "color: red" })
City @Html.TextBoxFor(model => Model.DoctorRegistration.City, new { @class = "form-control", @id = "txtCity", placeholder = "Enter the City Name" }) @Html.ValidationMessageFor(model => Model.DoctorRegistration.City, null, new { @style = "color: red" })
Pincode @Html.TextBoxFor(model => Model.DoctorRegistration.Pincode, new { @class = "form-control", @id = "txtPincode", placeholder = "Enter the Pincode" }) @Html.ValidationMessageFor(model => Model.DoctorRegistration.Pincode, null, new { @style = "color: red" })
Country Code @Html.DropDownList("CountryCode", null, "--- Select Country Code ---", new { @class = "select2-arrow" }) @Html.ValidationMessageFor(model => Model.DoctorRegistration.CountryCode, null, new { @style = "color: red" })
Mobile Number @Html.TextBoxFor(model => Model.DoctorRegistration.Mobile, new { @class = "form-control", @id = "txtMobile", placeholder = "Enter the Mobile Number" }) @Html.ValidationMessageFor(model => Model.DoctorRegistration.Mobile, null, new { @style = "color: red" })
Phone @Html.TextBoxFor(model => Model.DoctorRegistration.Phone, new { @class = "form-control", @id = "txtPhone", placeholder = "Enter the Phone Number" })
Email @Html.TextBoxFor(model => Model.DoctorRegistration.Email, new { @class = "form-control", @id = "txtEmail", placeholder = "Enter the Email" }) @Html.ValidationMessageFor(model => Model.DoctorRegistration.Email, null, new { @style = "color: red" })
Website @Html.TextBoxFor(model => Model.DoctorRegistration.Website, new { @class = "form-control", @id = "txtWebsite", placeholder = "Enter the Website" })
Aadhaar Card Number @Html.TextBoxFor(model => Model.DoctorRegistration.AadhaarCardNo, new { @class = "form-control", @id = "txtAadhaarCardNo", placeholder = "Enter the AadhaarCard NUmber" })
Language English,Tamil
AboutDoctor @Html.TextAreaFor(model => Model.DoctorRegistration.AboutDoctor, new { @class = "form-control maxlength-simple", @id = "txtAboutDoctor", maxlength = "500", placeholder = "Max length 500 chars" })
Status ---Select Status--- Active InActive
Upload Company Logo Choose file
Perview Image Remove
@ViewBag.MessageAjax method:
C#
function GetInfo() { var gender = $("input[name='optionsRadios']:checked").val(); var postedFile = $("#txtUploadImage").val(); var Doctor = { Tittle: $("#txtTittle").val(), DoctorName: $("#txtDoctorName").val(), DoctorCode: $("#txtDoctorCode").val(), RegistrationNo: $("#txtRegistrationNo").val(), Gender: gender, DocDOB: $("#txtDocDOB").val(), DocAddress1: $("#txtDocAddress1").val(), DocAddress2: $("#txtDocAddress2").val(), Country: $("#Country").val(), State: $("#state").val(), City: $("#txtCity").val(), Pincode: $("#txtPincode").val(), CountryCode: $("#CountryCode").val(), Mobile: $("#txtMobile").val(), Phone: $("#txtPhone").val(), Email: $("#txtEmail").val(), Website: $("#txtWebsite").val(), AadhaarCardNo: $("#txtAadhaarCardNo").val(), Language: $("#txtLanguage").val(), AboutDoctor: $("#txtAboutDoctor").val(), Status: $("#Status").val() }; var mainModel = {}; mainModel.DoctorRegistration = Doctor; $.ajax({ type: "POST", url: "/Doctor/AddDoctor", data: JSON.stringify(mainModel, postedFile), contentType: "application/json; charset=utf-8", dataType: "json", success: OnSuccess, failure: function (response) { alert(response.d); } }); } function OnSuccess(response) { //alert(response.id); if (response.id > 0) { var linkHref = "tabs-1-tab-1"; } }Controller:
C#
[HttpPost] public ActionResult AddDoctor(DoctorMainModel mainModel, HttpPostedFileBase postedFile) { try { Country_Bind(); CountryCode_Bind(); if (ModelState.IsValid) { DoctorReg obj = new DoctorReg(); int id = obj.AddDoctorRegistration(mainModel); if (id != 0) { Session["docID"] = id.ToString(); AddDoctorImage(postedFile); ViewBag.Message = "Company added successfully"; return Json(new { id = Session["docID"] }); } } return View(); } catch { return View(); } } private void AddDoctorImage(HttpPostedFileBase postedFile) { int docId = Convert.ToInt32(Session["docID"]); if (postedFile != null) { string path = Server.MapPath("~/Doctor/"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } var filename = docId.ToString() + ".png"; postedFile.SaveAs(path + filename); ViewBag.Message = "File uploaded successfully."; } }

All value pass to the controller but postedFile value am not getting




Raja Mouli AnkireddyRank #7,043 · 250 reputationPosted Oct 24, 2017, 8:45 AM EDT