MVC :: Keep Values Of Model's Unused Members During Updates?

Apr 2, 2010

suppose our model has a property named "CreatedByUserId" that keeps the creator's user id

when we want to update our model, there are no need to display this field, but we should keep it's value during the update.

so, if i don't place any edit field for this property on the view, the model wouldn't have any value for CreatedByUserId property when returns to controller

to solve this, i :

1.place a hidden input in the view for these fields (which is vulnerable)

or

2.make a Get call to db and get the original CreatedByUserId value on each update (which causes additional round trips to db)

isn't there any better way to do this ?

View 6 Replies


Similar Messages:

MVC :: Level Model Members - Add Validation Support To TextRef Items

Mar 31, 2011

i'm working on a MVC3 webapp and my Model consist of many classes that use a custom type (TextRef) for textual properties. for example my Product entity looks like :

[Code]....

TextRef :

[Code]....

so in my views i'm using :

[Code]....

how could i add validation support to TextRef items ? for example making Product.Title required

View 5 Replies

Best Practices Concerning View Model And Updates With Subset Of Fields

Jan 17, 2010

By picking MVC for developing our new site, I find myself in the midst of "best practices" being developed around me in apparent real time. Two weeks ago, NerdDinner was my guide but with the development of MVC 2, even it seems outdated. It's an thrilling experience and I feel privileged to be in close contact with intelligent programmers daily. Right now I've stumbled upon an issue I can't seem to get a straight answer on - from all the blogs anyway - and I'd like to get some insight from the community. It's about Editing (read: Edit action). The bulk of material out there, tutorials and blogs, deal with creating and view the model.

So while this question may not spell out a question, I hope to get some discussion going, contributing to my decision about the path of development I'm to take. My model represents a user with several fields like name, address and email. All the names, in fact, on field each for first name, last name and middle name. The Details view displays all these fields but you can change only one set of fields at a time, for instance, your names. The user expands a form while the other fields are still visible above and below. So the form that is posted back contains a subset of the fields representing the model. While this is appealing to us and our layout concerns, for various reasons, it is to be shunned by serious MVC-developers.

I've been reading about some patterns and best practices and it seems that this is not in key with the paradigm of viewmodel == view. Or have I got it wrong? Anyway, NerdDinner dictates using FormCollection och UpdateModel. All the null fields are happily ignored. Since then, the MVC-community has abandoned this approach to such a degree that a bug in MVC 2 was not discovered. UpdateModel does not work without a complete model in your formcollection. The view model pattern receiving most praise seems to be Dedicated view model that contains a custom view model entity and is the only one that my design issue could be made compatible with.

It entails a tedious amount of mapping, albeit lightened by the use of AutoMapper and the ideas of Jimmy Bogard, that may or may not be worthwhile. He also proposes a 1:1 relationship between view and view model. In keeping with these design paradigms, I am to create a view and associated view for each of my expanding sets of fields. The view models would each be nearly identical, differing only in the fields which are read-only, the views also containing much repeated markup. This seems absurd to me. In future I may want to be able to display two, more or all sets of fields open simultaneously.

View 5 Replies

Forms Data Controls :: DataList - Updates Show Original Values Not Updated Values?

Jun 3, 2010

Updates to the edited item are not passing the new / updated values but rather the original values. And I can't for the life of me figure out why when I change the original value in an edit textbox and post the update the new value is not being passed. I get the original value. Perhaps fresh eyes can spot the problem. This should be super basic but apparently I'm missing something.

Here's the code for the Item and Edit templates. The code behind is below this.

[Code]....

Code behind begins here....

[Code]....

View 2 Replies

Security :: Filtering Members List / Only Members Whose Name Contains The Typed Characters Will Show Up In The Gridview?

Apr 28, 2010

Our site has a page for maintenance of existing members (e.g. adding / changing roles, etc.)This page currently uses a gridview to show a complete list of all members, based on GetMembers() method to populate it.However, as the number of users has grown to several hundred, it has become difficult to locate a particular user by paging through several pages.Is there a way to narrow down this list, maybe with a filtering textbox, so that as you start typing into that textbox, only members whose name contains the typed characters will show up in the gridview?

View 8 Replies

Not Able To Retain HiddenField Values When Using AJAX Updates In .Net

Aug 20, 2010

I have a hidden field which is used to count the number of times "Load Grid" button is clicked. Load Grid button and the grid view are in update panel as shown below.

[Code]....

Code behind:
public partial class ajaxGridSort : System.Web.UI.Page
{
public string sortOrder
{
get [code]....
Each time user clicks on load grid or try to sort in the grid, I am loosing the hidden field values. Can you please help me understand why am I loosing hidden field data on AJAX postback and please provide the solution for this issue?

View 2 Replies

MVC :: Model State Doesn't Contain Model Values

Aug 2, 2010

when I use Html.HiddenFor( model => model.OwnerId ) to create a hidden field, the value assigned to that field is zero. When I use <input type="hidden" value="<%: Model.OwnerId %>" /> to add the hidden field to the form, the value is assigned correctly.

Why would Html.HiddenFor( model => model.OwnerId ) not get the correct value from the Model object? Am I supposed to load model state somehow separate from returning the model object from the action method? Here is the view:

[Code]....

The Create action method is relatively straight forward.

public ActionResult Create( ... )
{
ViewStockItem item = new ViewStockItem();
item.ActionCode = ActionCode.Add;
if (item.OwnerId == 0)
item.OwnerId = 7;
BookOwner owner = db.BookOwners.Single(c => c.OwnerId == item.OwnerId);
item.OwnerName = owner.OwnerName;
return View(item);
}

View 4 Replies

Data Controls :: DropDownList Inside GridView EditItem Template Updates NULL Values When Using SqlDataSource UpdateCommand

May 7, 2015

On update the dropdown value shows NULL in database : here's structure for my gridview 

<asp:TemplateField HeaderText="Construction Phase" SortExpression="Phase_Name">
<EditItemTemplate>
<asp:DropDownList ID="EditedDropDownInGrid" runat="server" CssClass="form-control" DataSourceID="PhaseSQLDataSource" DataTextField="pp_name" DataValueField="pp_id">
</asp:DropDownList>
</EditItemTemplate>

[Code] ....

It updates other controls in gridview but does not update my selected dropdowns item value in Integer format which is inside gridview...

View 1 Replies

AJAX :: Programming Model - Getting Values Of Dropdownlists

Feb 6, 2010

Imagine I'm developing a webform with two dropdownlists and a submit button. The second dropdownlist depends on the choice in the first, and both are loaded dynamically using webmethods being called with javascript in de ASPX page (ajax). When I submit the form to the server, to save the data, I can't get the value of those dropdownlists. I think it is because with client AJAX no viewstate data is being generated. I need to send the data to the server and save the webform data, and identify wich data is on each webcontrol.

View 3 Replies

How To Set Values For Model Properties On .aspx Page In MVC 2

Dec 3, 2010

I have a strongly typed view. I get model passed into the view and then i assign model values to labels etc.
I would then also like to set Model values programmatically on .aspx page, like:

<%= Model.someValue = "foo"; %>

and then pass that model back to controller action and than access those values. I know that I can apply values to model like these:

<%= Html.TextBoxFor(n => n.someValue) %>

but in these case, this is not an option for me.

View 2 Replies

MVC :: Passing Values From Model To Javascript (JQuery)?

Jun 18, 2010

i have a simple model [Code]....

when i render a view to show the data inside the model, i also need to write some javascript

how to get the ID value in the script from the View?

View 3 Replies

AJAX :: Passing Values From Model Pop Up To Text Box?

Nov 30, 2010

Am using a Model popup to show a grid view. From where the selected record should be posted back to a Text Box in the parent page. i loaded the grid succesfully i can post the values inside the modelpopup. but can't post the value to the text box in the parent page. and i use only server side code not client side scripting.

View 2 Replies

Read Model Values And Send Them By Ajax Post?

Feb 17, 2011

I have the following code and it`s pointing out errors as follows

Error 1 The name 'date' does not exist in the current context
Error 2 The name 'person' does not exist in the current context

What is wrong?

$("#test").Click(function () {
var date = $("#DateFrom").val();
var person = Model.SelectedPerson;
$.ajax({
url: '@Url.Action("testEmp","Employee",new {dateFrom = date, selectedPerson= person})',
type: 'GET',
contentType: "application/json; charset=utf-8",
dataType: "html",
success: function (result) {
$('#text).html(result);
},
});
return false;
});

View 1 Replies

Web Forms :: How To Use Unused Variables In Code

Feb 25, 2011

I am building an application in ASP.NET(C#). In certain forms I have many unused Varibales (declared as global variables).

I want to know whether these variables takes any memory space when i build the application.

For instance

public string _ID;
public string _Name;

View 3 Replies

MVC :: Model Binding Values In HTML Table Back To Controller

Aug 25, 2010

Currently, I am working with ASP.NET MVC1 and am still learning about Model Binding and how values from a View are passed back to the Controller / Model. Specifically, I want take an existing Model, create a Table and populate the Rows of the Table, allow the user to edit some fields and pass it back. In my example, I have a Class called "Ingredient" which has 4 public accessories: Name, Barcode, Amount, and Unit.
[Code]....

Or is this not possible? (Basically, I'm trying to re-create a datagrid where certain fields are editable and certain are not...)

View 2 Replies

Custom Model Binder Option In MVC 2 RC - How To Iterate Over Form Values

Feb 2, 2010

I'm using the MVC 2 RC. I have a custom model binder that used to iterate over posted form values in MVC 1.0 like this:

[Code]....

View 2 Replies

MVC2 Model Binding Does Not POST Back Hidden Values?

Jul 25, 2010

I have a /Register [GET] Action in the controller that pre-poluates a view-model with a string and an integer and returns: return View(myModel);I can see the string being populated in the textarea and the id being populated in a hidden input. Yet when the form gets POSTed, the string value is null and the int value is 0. I verified that both values are posted to the server but the model received in the POST action is missing those values.

View 1 Replies

SQL Reporting :: It Is Possible To Remove Unused Legends From Chart

Feb 2, 2010

It is possible to remove unused legends from chart.

For Example.

in below chart Pen-$ and Book-Rs is unused . How to hide these ones.

View 1 Replies

Visual Studio :: How To Remove Unused Css Items

Jan 28, 2010

Is there a way to easily tell which items in my css file are not used on any of my pages? I am trying to avoid going through each page individually.

View 1 Replies

Visual Studio :: How To Remove Unused <%@ Register

Apr 11, 2010

Our project has been really more and more 'messy' due to many programmers and no real control over the project.

Is there a way to automatically remove all <%@ Register... references in the project?

View 2 Replies

What Happens With Unused Properties Of A Class When An Object Is Instantiated

Aug 5, 2010

I am interested to know what happens with unused properties of a class when an object is instantiated?

Are there performance hits for having additional unused properties? What about complex properties that are accessing the database, but I'm not using them, are they still being loaded?

View 1 Replies

VS2010 - How To Delete Unused Images / Files

Mar 21, 2011

In a webapplication we have a lot of images and some of them are not used/referenced anymore. Is there way (tool or something) to get a list of all these unused files or/and delete them?

View 1 Replies

Visual Studio :: Identifying Unused Properties In The Project?

Feb 17, 2010

i am working on asp.net application using C#, identifying properties that are unused in my project. in Code analysis tool i am able to see unused private fields getting reported (Avoid unused private fields), but is there any such facility too for unused Properties declared in the class.

View 3 Replies

How To Automatically Remove Unused (expired) Items From Session

Oct 28, 2010

I need functionality that will allow to discard objects from session if they are not used in specified amount of time. It is simmilar to Cache timeout functionality.

Is there any session provider (possibly free) or pattern that achieves that?

View 2 Replies

Will Commenting-out Unused Code Give Page A Performance Boost In Any Way, Shape, Or Form

Aug 2, 2010

Okay so my situation at work is that I've written about 200 or so lines of additional functionality into an aspx page's code-behind that is currently not to be implemented. It is in a subroutine that handles an event that currently has zero chance of occurring.

Because this code is not being used, I've gotten curious. Should I comment out the subroutine that has zero chance of firing? Would it do anything to enhance the performance of the page or anything like that if I did indeed comment it out? Or could/should I just leave it as is?

View 4 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved