Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6932205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:40:35+00:00 2026-05-27T11:40:35+00:00

I am writing an image upload form using ASP.NET MVC 3. In the view,

  • 0

I am writing an image upload form using ASP.NET MVC 3.

In the view, please notice that I am displaying @Model.ImagePath as text and as a @Html.TextBoxFor(model => model.ImagePath).

View:

@using (Html.BeginForm(null, null, FormMethod.Post, new { enctype="multipart/form-data" }))
{
    @Html.HiddenFor(model => model.BannerSlideId)
    @Html.HiddenFor(model => model.Key)
    <p>
    Image Path:@(Model.ImagePath)<br />
    Image Path in TextBoxFor: @Html.TextBoxFor(model => model.ImagePath)
    </p>
    <p>
        <label class="styled">Upload Slide Image</label>
        <input type="file" name="image" />
    </p>
    <p>
        <button type="submit">Save</button> @Html.ActionLink("Back to List", "Index")
    </p>
}

I then select an image using the file input, and I submit the form to the Controller.

Controller action:

[HttpPost]
public ActionResult Create(BannerSlide model, HttpPostedFileBase image)
{
    if (image != null)
        model.ImagePath = image.FileName;
    return View("Edit", model);
}

When I debug with a breakpoint, the image.FileName string is assigned to model.ImagePath. However, when I get back to the View I get Two different values from ImagePath.

Results

Image Path:@(Model.ImagePath)<br />

Correctly returns the image filename that was assigned. But,

Image Path in TextBoxFor: @Html.TextBoxFor(model => model.ImagePath)

Incorrectly returns blank!

Any ideas for why this is happening?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T11:40:36+00:00Added an answer on May 27, 2026 at 11:40 am

    You should remove the ImagePath property from ModelState if you intend to modify it in your POST controller action or HTML helpers such as TextBoxFor will first look for a value inside ModelState when binding and then in the model:

    if (image != null)
    {
        ModelState.Remove("ImagePath");
        model.ImagePath = image.FileName;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing an upload handler (asp.net) to handle image uploads. The aim is
I am writing a small image/video upload program using WCF REST. Ideally, I would
I am writing a simple Book create page in ASP.NET MVC. User can create
I'm writing the PHP/webserver side of an image upload for an iOS app. Using
I'm writing an application that allows users to upload images onto the server. I
I'm writing a C++ library for an image format that is based on PNG.
I'm writing a WPF application and trying to bind an image to my view
I'm writing a function that fishes out the src from the first image tag
I'm writing a web app that at one point allows a user to upload
I'm writing an simple application for users to upload an image, modify it and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.