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

  • SEARCH
  • Home
  • 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 9230141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:45:01+00:00 2026-06-18T05:45:01+00:00

So in my view, I just want to be able to read the values

  • 0

So in my view, I just want to be able to read the values provided by the Model.

@{
    var bgPath = "../Files/somedir/" + Model.FilePath;
}

So I can just dump it into a string to render an image to the DOM:

 <img id="bg-image" class="background-image" src="@bgPath" draggable ="false" alt="" />

Now, this works perfectly fine. My view renders properly. My problem is that when the form is submitted, it throws up an error that Model.FilePath is null.

The code is already OUTSIDE the main (and only) form field in the view.

I do not want to bind this data, I’m ONLY using it to give values to js. I have many other fields that seemed like they were going to work and there’s not really the option of changing it without a load of rewrite.

So my question is, how to get read-only model values?

  • 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-06-18T05:45:03+00:00Added an answer on June 18, 2026 at 5:45 am

    you need to keep that in a hidden field in your form so that MVC model binding will make it available when submitting form.

    @using(Html.Beginform())
    {
       @Html.HiddenFor(x=>x.FilePath)
       //other elements also 
       <input type="submite" />
    }
    

    But remember that, the hidden value field can be changed using browser extensions (like firebug) before posting. So If you are not updating the filepath by reading a new value from the user, do either one of this

    1) Update only the relevant fields. Have an Update method which updates only the relevant fields for the model.

     public bool UpdateCustomer(string name,string description,int id);
    

    2) If updating all fields, Read from the domain object first and the update

    [HttpPost]
    public ActionResult Edit(YourViewModel model)
    {
      var domainObject=repo.GetCustomerFromID (model.ID)
      //update only the relevant fields on loaded domain object
      domainObject.Description=model.Description;
      repo.SaveCustomer(domainObject);
      return RedirectToAction("Success");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, I just want to be able to get the parameter community_name, can this
I've created a custom view class and right now just want to draw an
I want to force my view to go for landscape, just when I call
i have just started playing aorund with asp.net mvc and i want to view
I've just created a new view based application, and now I want to set
Really simple but just not getting it. I want to reference a view by
I have ItemsControl which I bind to ObservableCollection On my view model I just
I want to be able to read the headers sent back from a webpage
I just first want to say, thanks for taking the time to read this!
I currently have a catalog of files I want to read into my program

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.