Click here to Skip to main content
11,718,589 members (84,581 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: Framework entity MVC3

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 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)
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 7:55am
Edited 10-Mar-13 8:01am

1 solution

Rate this: bad
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:[^]
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 Sergey Alexandrovich Kryukov 651
1 OriginalGriff 210
2 F-ES Sitecore 185
3 Jochen Arndt 160
4 Maciej Los 130
0 OriginalGriff 535
1 Maciej Los 529
2 Richard MacCutchan 440
3 CHill60 415
4 F-ES Sitecore 415

Advertise | Privacy | Mobile
Web04 | 2.8.150901.1 | Last Updated 10 Mar 2013
Copyright © CodeProject, 1999-2015
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