4,815 questions
The Form action does not populate the @ViewBag.candidatelist.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
public void candidatename()
{
List<SelectListItem> name = new List<SelectListItem>();
string apiUrl = "http://localhost:54621/api/mim/candidate/GetCandidates";
Util du = new Util();
string respText = "";
string isErr = "";
respText = du.CallingAPI(out isErr, apiUrl);
respText = respText.TrimStart('\"');
respText = respText.TrimEnd('\"');
respText = respText.Replace("\\", "");
List<SelectListItem> candidatelist = new List<SelectListItem>();
Interviewer obj = new Interviewer();
List<Interviewer> objLst = new List<Interviewer>();
if (isErr != "Err" && isErr != "err")
{
List<JObject> ob = JsonConvert.DeserializeObject<List<JObject>>(respText);
foreach (JObject job in ob)
{
SelectListItem s = new SelectListItem
{
Value = job.Property("Id").Value.ToString(),
Text = job.Property("Candidatename").Value.ToString()
};
candidatelist.Add(s);
}
}
candidatelist.Insert(0, new SelectListItem { Text = "--Select--", Value = "0" });
ViewBag.candidatelist = candidatelist;
}
[HttpPost]
public ActionResult Form(Candidate s)
{
HttpClient client = new HttpClient();
client.BaseAddress = new Uri("http://localhost:54621/api/mim/candidate/SaveC");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = client.PostAsJsonAsync("http://localhost:54621/api/mim/candidate/SaveC", s).Result;
string result = response.Content.ToString();
return View();
}
@model Form3.Models.Interviewer
@{
ViewData["Title"] = "Form";
}
<h2>Form</h2>
<h4>Interviewer</h4>
<hr />
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label asp-for="Candidatename" class="control-label"></label>
<select asp-items="@(new SelectList(@ViewBag.candidatelist, "Value", "Text", @ViewBag.candidatelistSelected))" class="form-control" id="ddlApplication" onchange="ShowAPI('')"></select>
</div>
<form asp-action="Form">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="Candidatename" class="control-label"></label>
<div>
<label>@ViewBag.d</label>
</div>
</div>
<div class="form-group">
<label asp-for="Dateofinterview" class="control-label"></label>
<div>
<lebel>@ViewBag.a</lebel>
</div>
<div>
<label asp-for="Timeofinterview" class="control-label"></label>
<div>
<lebel>@ViewBag.b</lebel>
</div>
</div>
<label asp-for="Postappliedfor" class="control-label"></label>
<div>
<label>@ViewBag.c</label>
</div>
@*<select asp-items="@(new SelectList(@ViewBag.candidatedatelist, "Value", "Text", @ViewBag.candidatedatelistSelected))" onchange="FillModel();" class="form-control" ></select>*@
</div>
@*<div class="form-group">
<label asp-for="Timeofinterview" class="control-label"></label>
<select asp-items="@(new SelectList(@ViewBag.candidatetimelist, "Value", "Text", @ViewBag.candidatetimelistSelected))" onchange="FillModel();" class="form-control"></select>
</div>
<div class="form-group">
<label asp-for="Postappliedfor" class="control-label"></label>
<select asp-items="@(new SelectList(@ViewBag.candidatepostlist, "Value", "Text", @ViewBag.candidatepostlistSelected))" onchange="FillModel();" class="form-control"></select>
</div>
<div class="form-group">
<label asp-for="Overallhrrating" class="control-label"></label>
<select asp-items="@(new SelectList(@ViewBag.candidateratinglist, "Value", "Text", @ViewBag.candidateratinglistSelected))" onchange="FillModel();" class="form-control"></select>
</div>*@
<div class="form-group">
<label asp-for="technicalskills" class="control-label"></label>
<div>
<input type="radio" id="1" name="technicalskills" value="1" class="form-check-input">
<label for="1" style="color:orange">★</label><br>
<input type="radio" id="2" name="technicalskills" value="2" class="form-check-input">
<label for="2" style="color:orange">★★</label><br>
<input type="radio" id="3" name="technicalskills" value="3" class="form-check-input">
<label for="3" style="color:orange">★★★</label><br>
<input type="radio" id="4" name="technicalskills" value="4" class="form-check-input">
<label for="4" style="color:orange">★★★★</label><br>
<input type="radio" id="5" name="technicalskills" value="5" class="form-check-input">
<label for="5" style="color:orange">★★★★★</label><br>
</div>
<span asp-validation-for="technicalskills" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="interviewerremarks" class="control-label"></label>
<div>
<input type="radio" id="1" name="interviewerremarks" value="1" class="form-check-input">
<label for="1" style="color:yellow">★</label>
<input type="radio" id="2" name="interviewerremarks" value="2" class="form-check-input">
<label for="2" style="color:yellow">★★</label>
<input type="radio" id="3" name="interviewerremarks" value="3" class="form-check-input">
<label for="3" style="color:yellow">★★★</label>
<input type="radio" id="4" name="interviewerremarks" value="4" class="form-check-input">
<label for="4" style="color:yellow">★★★★</label>
<input type="radio" id="5" name="interviewerremarks" value="5" class="form-check-input">
<label for="5" style="color:yellow">★★★★</label>
</div>
<span asp-validation-for="interviewerremarks" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="statusfornextround" class="control-label"></label>
<div>
<input type="checkbox" id="SELECTED" name="statusfornextround" value="SELECTED" onclick="onlyOne(this)" class="form-check-input">
<label for="SELECTED"> SELECTED</label>
<input type="checkbox" id="REJECTED" name="statusfornextround" value="REJECTED" onclick="onlyOne(this)" class="form-check-input">
<label for="REJECTED"> REJECTED</label>
<input type="checkbox" id="NOSHOW" name="statusfornextround" value="NOSHOW" onclick="onlyOne(this)" class="form-check-input">
<label for="NOTSHOW">NO SHOW</label>
</div>
<span asp-validation-for="statusfornextround" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Remark" class="control-label"></label>
<textarea id="HRremarks" name="HRremarks" rows="4" cols="50" class="text-danger">
@*<input asp-for="Remark" class="form-control" />*@
Feedback.
</textarea>
<span asp-validation-for="Remark" class="text-danger"></span>
</div>
<div class="form-group">
<input type="submit" value="Create" class="btn btn-default" onchange="alert('Selected');" />
</div>
</form>
</div>
</div>
<script>
function onlyOne(checkbox) {
var checkboxes = document.getElementsByName('statusfornextround')
checkboxes.forEach((item) => {
if (item !== checkbox) item.checked = false
})
}
function ShowAPI(SubApp) {
var AppID = $('#ddlApplication').val();
//var ddlSubApp = $('#ddlSubApp');
alert(AppID);
$.ajax({
url: "../Candidate/Getcandidatedetail",
data: "{ 'Id': '" + AppID + "'}",
type: "Post",
contentType: "application/json;charset=utf-8",
success: function (data) {
//alert(AppID)
},
failure: function (data) {
alert(data.statusText);
},
error: function (error) {
alert(error.statusText);
}
});
}
</script>
<div>
<a asp-action="Index">Back to List</a>
</div>
At the time of saving showing error
An unhandled exception occurred while processing the request.
ArgumentNullException: Value cannot be null.
Parameter name: items
Microsoft.AspNetCore.Mvc.Rendering.MultiSelectList..ctor(IEnumerable items, string dataValueField, string dataTextField, IEnumerable selectedValues, string dataGroupField)
Stack Query Cookies Headers
ArgumentNullException: Value cannot be null. Parameter name: items
Microsoft.AspNetCore.Mvc.Rendering.MultiSelectList..ctor(IEnumerable items, string dataValueField, string dataTextField, IEnumerable selectedValues, string dataGroupField)
Microsoft.AspNetCore.Mvc.Rendering.SelectList..ctor(IEnumerable items, string dataValueField, string dataTextField, object selectedValue)
CallSite.Target(Closure , CallSite , Type , object , string , string , object )
AspNetCore.Views_Candidate_Form.ExecuteAsync() in Form.cshtml
+
<select asp-items="@(new SelectList(@ViewBag.candidatelist, "Value", "Text", @ViewBag.candidatelistSelected))" class="form-control" id="ddlApplication" onchange="ShowAPI('')"></select>
Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageCoreAsync(IRazorPage page, ViewContext context)
Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageAsync(IRazorPage page, ViewContext context, bool invokeViewStarts)
Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderAsync(ViewContext context)
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, string contentType, Nullable<int> statusCode)
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ActionContext actionContext, IView view, ViewDataDictionary viewData, ITempDataDictionary tempData, string contentType, Nullable<int> statusCode)
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor.ExecuteAsync(ActionContext context, ViewResult result)
Microsoft.AspNetCore.Mvc.ViewResult.ExecuteResultAsync(ActionContext context)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeResultAsync(IActionResult result)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResultFilterAsync<TFilter, TFilterAsync>()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResultExecutedContext context)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.ResultNext<TFilter, TFilterAsync>(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeResultFilters()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()
Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
The Form action does not populate the @ViewBag.candidatelist.