Click here to Skip to main content
15,886,075 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
HTML
<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
Updated 10-Mar-13 8:01am
v3

1 solution

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[^]
 
Share this answer
 
Comments
Ahamed Azeem 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ő 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900