Click here to Skip to main content
15,891,940 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My model is

[RegularExpression(@"([a-zA-Z0-9\s_\\.\-:])+(.png|.jpg|.gif)$", ErrorMessage = "Only Image files allowed.")]
		public HttpPostedFileBase Logo { get; set; }


my partial view is

@Html.ValidationSummary(true)
@using SocialMediaAnalytics.Web.Models;
@model SocialMediaAnalytics.Web.Models.Account.RegistrationModel
@using (Html.BeginForm("CreateDatabase", "Settings", FormMethod.Post, new { id = "formAddDatabaseandWorkSpace", encType = "multipart/form-data" }))
{
<div class="col-sm-12">
				<div class="form-group">
					<label>Logo</label>
					@Html.TextBoxFor(m => m.Logo, new { type = "file" })
				</div>
			</div>
		</div>
	</div>
	<div class="modal-footer">
		<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
		<button type="submit" class="btn btn-primary" id="btnAddDB">Save</button>

	</div>
}



and the controller is
[HttpPost]
		public JsonResult CreateDatabase(RegistrationModel model)
		{
			try
			{
                          else if(model.Logo!=null)
					{
					LogoUpload(model);
					return Json(new { title = "Upload Logo", 
                         message = "Logo uploaded successfully", type = "Success" });
						
					}
}
</pre

but the value for "Logo" in model is always null even after browsing the image.

What I have tried:

I have tried with  type instead of @Html.TextBoxFor() but its getting null everytime.
Posted
Comments
F-ES Sitecore 9-Feb-18 4:02am    
Logo is a textbox? It needs to be "<input type=file". Google "upload file mvc" to see some code samples of the basics.
Joy Sikdar 9-Feb-18 4:03am    
how could i bind my model to input type?
F-ES Sitecore 9-Feb-18 4:11am    
Sorry, I didn't see the type=file attribute :o that should work
Joy Sikdar 9-Feb-18 4:17am    
yes I also think so..But its getting null always.
F-ES Sitecore 9-Feb-18 4:24am    
I just tried your code and it works ok for me. Check nothing else is interfering, like code you haven't posted (js etc).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900