Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Framework entity MVC3
Hi,
 
I have a table called contract, has following fields
 
Id(uniqueidentifier),contractno(int), personname(varchar(50)),NationalityId(fk,uniqueidentifier),
OccupationId(FK,uniqueidentifier), SalaryId(fk,Uniqueidentifier).
 
Salary has been defined in the salarydetails table with the following fields based on occupation and nationality
 
Id(pk,unique identifier),OccupationId(fkuniqueidentifier,ud),NationalityId(fk,uniqueidentifier),salary(int)
 
I am using asp.net mvc to create a contract, which is working fine
 
but the problem is in edit, which loads the data, but while saving salary id is missing, so model.isvalid is becomes false
 
The code in the view is given below
   <div class="editor-field">
            @Html.TextBoxFor(model => model.SalaryDetail.Salary)
            @Html.ValidationMessageFor(model => model.SalaryId)
   </div>
Instead of salarydetail.salary, if I put SalaryId then the edit form loads the id instead of salary value from the table, in the case its working but i supposed to display the salary not the id
 
Your help will be much appreciated.
 
[Edit]Code block added[/Edit]
Posted 10-Mar-13 8:55am
Edited 10-Mar-13 9:01am
ProgramFOX131.4K
v3

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

It depends on your model too. But I suppose you don't want the user to enter GUID's, and you won't be able to make editor for a referenced fields - it is not in the scope of your edited model instance (you could however display it). It looks to me that you need to use a DropDownList there. There are several alternatives how to populate it, look here for one of them: http://odetocode.com/blogs/scott/archive/2010/01/18/drop-down-lists-and-asp-net-mvc.aspx[^]
  Permalink  
Comments
Ahamed Azeem at 10-Mar-13 14:12pm
   
yes I suppose dont want the user to enter guids but so what can i do is i can disable the textbox so the value cannot be changed but user can just see it. The problem is only if I put the guid value on the textbox its inserted otherwise its not, i suppose not to display the guid but to display the value associated with the guid
Zoltán Zörgő at 10-Mar-13 16:58pm
   
Simply use @model.SalaryDetail.Salary. Or build a field on it manually. And use an input model for editing, not the original data model - it is also a security consideration.

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

  Print Answers RSS
0 OriginalGriff 270
1 Sergey Alexandrovich Kryukov 185
2 BillWoodruff 173
3 CPallini 155
4 Kamal Rocks 144
0 OriginalGriff 5,655
1 DamithSL 4,506
2 Maciej Los 3,997
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,180


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 10 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100