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
Raju Fodse
1.5k
244
31k
Dropdownlist with JQuery using If Condition
Aug 10 2017 3:04 AM
I want create Dropdownlist using Jquery but I am not able to get Result
public
JsonResult GetPipeNo(
string
MyStageCode)
{
db.Configuration.ProxyCreationEnabled =
false
;
if
(MyStageCode ==
"P3"
)
{
List<PipeAl> PipeList = db.PipeAls.ToList();
return
Json(PipeList, JsonRequestBehavior.AllowGet);
}
else
{
List<Process> PipeList = db.Processes.Where(x => x.NextStageID == MyStageCode).ToList();
return
Json(PipeList, JsonRequestBehavior.AllowGet);
}
}
View Code is
@model EasyApp.Models.Process
@{
ViewBag.Title =
"Create"
;
}
<html>
<head>
<script src=
"~/Scripts/jquery-1.10.2.min.js"
></script>
<script src=
"~/Scripts/jquery-ui-1.12.1.js"
></script>
<link href=
"~/Content/jquery-ui.css"
rel=
"stylesheet"
/>
<script>
$(document).ready(function () {
$(
"#StageID"
).change(function () {
$.
get
(
"/Dailyproduction/GetPipeNo"
, { MyStageCode: $(
"#StageID"
).toString() }, function (data) {
$(
"#PIPENO"
).empty();
$.each(data, function (index, row) {
$(
"#PIPENO"
).append(
"<option value='"
+ row.PIPENO +
"'>"
+ row.PIPENO +
"</option>"
)
});
});
});
$(function () {
$(
"#datepicker"
).datepicker({
dateFormat:
'dd/mm/yy'
});
});
});
</script>
</head>
<body>
<h2>Add Daily Production</h2>
<div
class
=
"EasyViewDiv"
>
@
using
(Html.BeginForm())
{
@Html.AntiForgeryToken()
<div
class
=
"form-horizontal"
>
@Html.ValidationSummary(
true
,
""
,
new
{ @
class
=
"text-danger"
})
<div
class
=
"form-group"
>
@Html.LabelFor(model => model.StageID,
"Stage Name"
, htmlAttributes:
new
{ @
class
=
"control-label col-md-2"
})
<div
class
=
"col-md-10"
>
@
if
(ViewBag.StageID !=
null
)
{
@Html.DropDownListFor(model=>model.StageID, ViewBag.StageID
as
SelectList,
"-----Select Stage ID---"
,
new
{ @
class
=
"form-control"
})
}
@Html.ValidationMessageFor(model => model.StageID,
""
,
new
{ @
class
=
"text-danger"
})
</div>
</div>
<div
class
=
"form-group"
>
@Html.LabelFor(model => model.PRDate,
"Production Date"
, htmlAttributes:
new
{ @
class
=
"control-label col-md-2"
})
<div
class
=
"col-md-10"
>
@Html.TextBoxFor(model => model.PRDate,
new
{ id =
"datepicker"
, @
class
=
"form-control"
})
@Html.ValidationMessageFor(model => model.PRDate,
""
,
new
{ @
class
=
"text-danger"
})
</div>
</div>
<div
class
=
"form-group"
>
@Html.LabelFor(model => model.PIPENO,
"Pipe No"
, htmlAttributes:
new
{ @
class
=
"control-label col-md-2"
})
<div
class
=
"col-md-10"
>
@*@Html.DropDownList(
"PIPENO"
,
null
, htmlAttributes:
new
{ @
class
=
"form-control"
})*@
@Html.DropDownListFor(model => model.PIPENO,
new
SelectList(
""
),
"--Select PipeNO--"
,
new
{ @
class
=
"form-control"
})
@Html.ValidationMessageFor(model => model.PIPENO,
""
,
new
{ @
class
=
"text-danger"
})
</div>
</div>
<div
class
=
"form-group"
>
@Html.LabelFor(model => model.ATTNSYSID,
"Operator Name"
, htmlAttributes:
new
{ @
class
=
"control-label col-md-2"
})
<div
class
=
"col-md-10"
>
@*@Html.TextBoxFor(model => model.ATTNSYSID,
new
{ id =
"txtUserSearch"
, @
class
=
"form-control"
})*@
@*@Html.DropDownListFor(model => model.ATTNSYSID,
new
SelectList(
""
),
"--Select Operator--"
,
new
{ @
class
=
"form-control"
})*@
@Html.DropDownList(
"ATTNSYSID"
,
null
, htmlAttributes:
new
{ @
class
=
"form-control"
})
@Html.ValidationMessageFor(model => model.ATTNSYSID,
""
,
new
{ @
class
=
"text-danger"
})
</div>
</div>
<div
class
=
"form-group"
>
@Html.LabelFor(model => model.Status,
"Status"
, htmlAttributes:
new
{ @
class
=
"control-label col-md-2"
})
<div
class
=
"col-md-10"
>
@Html.EditorFor(model => model.Status,
new
{ htmlAttributes =
new
{ @
class
=
"form-control"
} })
@Html.ValidationMessageFor(model => model.Status,
""
,
new
{ @
class
=
"text-danger"
})
</div>
</div>
<div
class
=
"form-group"
>
@Html.LabelFor(model => model.NextStageID,
"Next Production Stage"
, htmlAttributes:
new
{ @
class
=
"control-label col-md-2"
})
<div
class
=
"col-md-10"
>
@
if
(ViewBag.StageID !=
null
)
{
@Html.DropDownListFor(model => model.NextStageID, ViewBag.StageID
as
SelectList,
"-----Select Stage ID---"
,
new
{ @
class
=
"form-control"
})
}
@*@Html.DropDownList(
"NextStageID"
,
null
, htmlAttributes:
new
{ @
class
=
"form-control"
})
@Html.DropDownListFor(model => model.NextStageID, ViewBag.NextStageList
as
SelectList,
"-----Select Next Stage ID---"
,
new
{ @
class
=
"form-control"
})*@
@Html.ValidationMessageFor(model => model.NextStageID,
""
,
new
{ @
class
=
"text-danger"
})
</div >
</div>
<div
class
=
"dropdown-menu"
></div>
<div
class
=
"form-group"
>
<div
class
=
"col-md-offset-2 col-md-10"
>
<input type=
"submit"
value=
"Create"
class
=
"btn btn-default"
/>
</div>
</div>
</div>
}
<div>
@Html.ActionLink(
"Back to List"
,
"Index"
)
</div>
</div>
</body>
</html>
Reply
Answers (
1
)
Edit and reflect that edit in DataTable (parent child page)
How can we do post call in Angular 4.0 with MVC controller ?