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 1054599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:25:53+00:00 2026-05-16T17:25:53+00:00

I have some fields in my ViewModel that I only need for the output

  • 0

I have some fields in my ViewModel that I only need for the output in my View. But they are always getting send when submitting the form. That’s not only annoying, but also dangerous, because I definitly don’t want that databinding for these viewmodel fields.

Are there any change to define a OneWay Databinding for some of my viewmodel properties?

Thx in advance

EDIT:

The problem ist, that the Pictures and ValidSizes List is send back to the server when I click to an ActionLink.

http://localhost:52176/?PageSize=30&Index=31&Pictures=System.Collections.Generic.List%601%5BSystem.String%5D&Size=100&ValidSizes=System.Collections.Generic.List%601%5BSystem.Web.Mvc.SelectListItem%5D

public class PicturesViewModel
{
    public const int SMALL = 100;
    public const int MIDDLE = 150;
    public const int BIG = 250;

    public int PageSize { get; set; }

    /// <summary>
    /// Initializes a new instance of the <see cref="PicturesViewModel"/> class.
    /// </summary>
    public PicturesViewModel()
    {
        Pictures = new List<string>();
        Size = SMALL;
        Index = 1;
        PageSize = 30;
    }

    /// <summary> Gets or sets the index. </summary>
    public int Index { get; set; }

    /// <summary>
    /// Gets or sets the picture links.
    /// </summary>
    /// <value>The picture links.</value>
    public List<string> Pictures { get; private set; }

    /// <summary>
    /// Gets or sets the size.
    /// </summary>
    /// <value>The size.</value>
    public int Size { get; set; }

    private List<SelectListItem> validSizes = null;

    /// <summary>
    /// Gets the valid sizes.
    /// </summary>
    /// <value>The valid sizes.</value>
    public IEnumerable<SelectListItem> ValidSizes
    {
        get {
            if (validSizes != null)
                return validSizes;

            validSizes = new List<SelectListItem>
            {
                new SelectListItem(){Text = "Small", Value = SMALL.ToString()},
                new SelectListItem(){Text = "Middle", Value = MIDDLE.ToString()},
                new SelectListItem(){Text = "Big", Value = BIG.ToString()}
            };

            return validSizes;
        }
    }
}

EDIT2:

    <div id="pager_left"> 
        <%= Html.ActionLink("Prev", "Prev", Model)%>
    </div></td>

That’s the Action Link that causes the binding.

  • 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-16T17:25:54+00:00Added an answer on May 16, 2026 at 5:25 pm
    1. Use separate ViewModel for form input
    2. Use IEnumerable instead of List
    3. Use [Bind(Exclude=”Pictures, ValidSizes”)] on the action input parameter
    4. Use private setters
    5. Don’t create form input elements for Pictures/ValidSizes if you don’t need them

    and so on.

    Update:

    You assign different ViewModel not to a view, but to the controller action that handles link click. And from your questions it seems that what you need is not “oneway” binding, but rather avoiding extra characters in URL – because, if your ValidSizes is IEnumerable it won’t be altered, and anyway in your URL its data is wrong, won’t cause update – so it’s already “one-way” binding.

    This is what I can find for your problem:
    http://forums.asp.net/t/1328683.aspx

    As for solution, I never use ActionLink helper myself, because it is a leaky abstraction and I don’t like to fight with it. Simple html link tag is always much better.

    <a href="<%= Html.BuildUrlFromExpression<>() %>" />
    

    I actually use my own few-lines version of the BuildUrlFromExpression for this. Also see in the link above how you can pass parameters via anonymous object instead of Model (new { PageSize = Model.PageSize, index = Model.index }).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some documents in couchdb that have fields that are arrays of id's
I have a table in database that is having some fields one of which
I have to prepare a report which is getting some fields data from conf
I have a viewmodel class for a create view that consists of 2 properties
I have a View that gets some bits of data via Action methods that
I have multiple MVC 3 forms that need form validation on certain fields (mostly
I have a form that will load some fields when the page is requested
i have some fields in my database table,and a field with phone name ,
I have a fieldset in which I have some input fields and a checkbox.
I use VB to get data through my form. I have some optional fields

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.