TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Aniket Narvankar
559
2.1k
605.4k
How to Select default value in dropdown in mvc base on condition
Apr 22 2021 5:29 AM
<select type="text" name="ErrorId" id="
[email protected]
"
onchange="if(ValidateCurrentRowError(this)) calculateQAScore('@Model.ICSDocNumber');">
<option>-select-</option>
@{
if( ViewBag.ErrorTypeMaster!=null){
foreach(var el in ViewBag.ErrorTypeMaster){
<option value="@el.Id" selected="@(el.Id==entity.ErrorId)"
data-error-category="@el.ErrorCategory"> @el.ErrorType </option>
}
}
}
</select>
I have a dropdown,in ViewBag.ErrorTypeMaster I have table in this format
Id ErrorId ErrorCategory ErrorType
1 10 Critical A
2 11 Critical B
3 12 Critical C
4 13 Critical D
When a page loads I am getting a value in one varriable that is departmentId,if departmentId is 7 I want by default D Errortype to be selected in drodpown. Kindly guide me on this. What changes I must do while binding dropdown
Reply
Answers (
4
)
Passing database data to _loginPartial.cshtml
Get record base on ID.