checkbox show null value not pass to controller mvc





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















I want to pass parameter value but when I click download error show AllDates show null value. Allstate is a checkbox for if check fetches all data if not check then put date from and Date to then fetch value. But All Date value not pass to the controller and show null value. Any expert tells me where I am wrong.



i am sharing error:




The parameters dictionary contains a null entry for parameter
'AllDates' of non-nullable type 'System.Boolean' for method
'System.Web.Mvc.ActionResult Index(Int32, Boolean, System.String,
System.String)' in
'Lead_Management_System.Controllers.ReportController'. An optional
parameter must be a reference type, a nullable type, or be declared as
an optional parameter. Parameter name: parameters




HTML



     @using (Html.BeginForm("Index", "Report"))
{
<div class="form-control">

Agent @Html.DropDownListFor(m => m.agentid, Model.SaleAgentList, new { id = "lblAgent" })


<div id="lblDate">
<br />
Followup Date <br /><br />
From: <input type="date" name="cmbSDate" id="cmbSDate" readonly="readonly" />
To: <input type="date" name="cmbTDate" id="cmbTDate" readonly="readonly" />
Select All : <input type="checkbox" name="AllData" id="AllData" onclick="mcheck()" checked /> <br /> <br />

</div>

<input type="submit" value="Download" />

</div>
}


Javascript



<script type="text/javascript">
function mcheck() {
if ($('#AllData').not(':checked').length) {
document.getElementById("cmbSDate").readOnly = false;
document.getElementById("cmbTDate").readOnly = false;
$("#AllData").attr('checked', false);

}
else {
document.getElementById("cmbSDate").readOnly = true;
document.getElementById("cmbTDate").readOnly = true;
$("#AllData").attr('checked', true);
}
}
</script>


Controller



 public ActionResult Index(int AgentID, bool AllDates, string DateFrom, string DateTo)
{
SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["Real"].ToString());
SqlCommand cmd = new SqlCommand("SP_rptAgentStatus", cn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@AgentID", AgentID);
cmd.Parameters.AddWithValue("@AllDates", AllDates);
cmd.Parameters.AddWithValue("@DateFrom", DateFrom);
cmd.Parameters.AddWithValue("@DateTo", DateTo);
DataTable dt = new DataTable();
SqlDataAdapter sda = new SqlDataAdapter(cmd);
sda.Fill(dt);

lstatus mls = new lstatus();

Reports.rptAgentStatus rpt = new Reports.rptAgentStatus();
rpt.SetDatabaseLogon("sa", "");
rpt.SetDataSource(dt);
rpt.SetParameterValue(0, "SUKH CHAYN RESIDENCE");
rpt.SetParameterValue(1, "Agent Status "+ DateTime.Parse(DateFrom).ToShortDateString() + DateTime.Parse(DateTo).ToShortDateString());
rpt.SetParameterValue(2, AgentID);
rpt.SetParameterValue(3, DateFrom);
rpt.SetParameterValue(4, DateTo);

Response.Buffer = false;
Response.ClearContent();
Response.ClearHeaders();


Stream str = rpt.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
str.Seek(0, SeekOrigin.Begin);
return File(str, "application/pdf", "rptAgentStatus.pdf");



}









share|improve this question




















  • 1





    not worked that much on mvc but in my previous company we used to have a hidden field to every radiobutton and use to set the hiddenfield value 1 and 0 and in modal we use bit and the name of the particular hidden field which works fine

    – user10249871
    Nov 29 '18 at 6:28











  • can you share a sample idea a just little bit in this scenario @Ibrahim shaikh

    – user2697533
    Nov 29 '18 at 6:32











  • You're declared bool AllDates as parameter but the checkbox has <input type="checkbox" name="AllData" id="AllData" onclick="mcheck()" checked />, which name attribute of the checkbox doesn't match with action parameter and returns null value. Why not use strongly-typed helpers like @Html.CheckBoxFor?

    – Tetsuya Yamamoto
    Nov 29 '18 at 6:33













  • i don't have model Allstate that's why I am not using strongly-typed @Tetsuya Yamamoto

    – user2697533
    Nov 29 '18 at 6:41


















1















I want to pass parameter value but when I click download error show AllDates show null value. Allstate is a checkbox for if check fetches all data if not check then put date from and Date to then fetch value. But All Date value not pass to the controller and show null value. Any expert tells me where I am wrong.



i am sharing error:




The parameters dictionary contains a null entry for parameter
'AllDates' of non-nullable type 'System.Boolean' for method
'System.Web.Mvc.ActionResult Index(Int32, Boolean, System.String,
System.String)' in
'Lead_Management_System.Controllers.ReportController'. An optional
parameter must be a reference type, a nullable type, or be declared as
an optional parameter. Parameter name: parameters




HTML



     @using (Html.BeginForm("Index", "Report"))
{
<div class="form-control">

Agent @Html.DropDownListFor(m => m.agentid, Model.SaleAgentList, new { id = "lblAgent" })


<div id="lblDate">
<br />
Followup Date <br /><br />
From: <input type="date" name="cmbSDate" id="cmbSDate" readonly="readonly" />
To: <input type="date" name="cmbTDate" id="cmbTDate" readonly="readonly" />
Select All : <input type="checkbox" name="AllData" id="AllData" onclick="mcheck()" checked /> <br /> <br />

</div>

<input type="submit" value="Download" />

</div>
}


Javascript



<script type="text/javascript">
function mcheck() {
if ($('#AllData').not(':checked').length) {
document.getElementById("cmbSDate").readOnly = false;
document.getElementById("cmbTDate").readOnly = false;
$("#AllData").attr('checked', false);

}
else {
document.getElementById("cmbSDate").readOnly = true;
document.getElementById("cmbTDate").readOnly = true;
$("#AllData").attr('checked', true);
}
}
</script>


Controller



 public ActionResult Index(int AgentID, bool AllDates, string DateFrom, string DateTo)
{
SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["Real"].ToString());
SqlCommand cmd = new SqlCommand("SP_rptAgentStatus", cn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@AgentID", AgentID);
cmd.Parameters.AddWithValue("@AllDates", AllDates);
cmd.Parameters.AddWithValue("@DateFrom", DateFrom);
cmd.Parameters.AddWithValue("@DateTo", DateTo);
DataTable dt = new DataTable();
SqlDataAdapter sda = new SqlDataAdapter(cmd);
sda.Fill(dt);

lstatus mls = new lstatus();

Reports.rptAgentStatus rpt = new Reports.rptAgentStatus();
rpt.SetDatabaseLogon("sa", "");
rpt.SetDataSource(dt);
rpt.SetParameterValue(0, "SUKH CHAYN RESIDENCE");
rpt.SetParameterValue(1, "Agent Status "+ DateTime.Parse(DateFrom).ToShortDateString() + DateTime.Parse(DateTo).ToShortDateString());
rpt.SetParameterValue(2, AgentID);
rpt.SetParameterValue(3, DateFrom);
rpt.SetParameterValue(4, DateTo);

Response.Buffer = false;
Response.ClearContent();
Response.ClearHeaders();


Stream str = rpt.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
str.Seek(0, SeekOrigin.Begin);
return File(str, "application/pdf", "rptAgentStatus.pdf");



}









share|improve this question




















  • 1





    not worked that much on mvc but in my previous company we used to have a hidden field to every radiobutton and use to set the hiddenfield value 1 and 0 and in modal we use bit and the name of the particular hidden field which works fine

    – user10249871
    Nov 29 '18 at 6:28











  • can you share a sample idea a just little bit in this scenario @Ibrahim shaikh

    – user2697533
    Nov 29 '18 at 6:32











  • You're declared bool AllDates as parameter but the checkbox has <input type="checkbox" name="AllData" id="AllData" onclick="mcheck()" checked />, which name attribute of the checkbox doesn't match with action parameter and returns null value. Why not use strongly-typed helpers like @Html.CheckBoxFor?

    – Tetsuya Yamamoto
    Nov 29 '18 at 6:33













  • i don't have model Allstate that's why I am not using strongly-typed @Tetsuya Yamamoto

    – user2697533
    Nov 29 '18 at 6:41














1












1








1








I want to pass parameter value but when I click download error show AllDates show null value. Allstate is a checkbox for if check fetches all data if not check then put date from and Date to then fetch value. But All Date value not pass to the controller and show null value. Any expert tells me where I am wrong.



i am sharing error:




The parameters dictionary contains a null entry for parameter
'AllDates' of non-nullable type 'System.Boolean' for method
'System.Web.Mvc.ActionResult Index(Int32, Boolean, System.String,
System.String)' in
'Lead_Management_System.Controllers.ReportController'. An optional
parameter must be a reference type, a nullable type, or be declared as
an optional parameter. Parameter name: parameters




HTML



     @using (Html.BeginForm("Index", "Report"))
{
<div class="form-control">

Agent @Html.DropDownListFor(m => m.agentid, Model.SaleAgentList, new { id = "lblAgent" })


<div id="lblDate">
<br />
Followup Date <br /><br />
From: <input type="date" name="cmbSDate" id="cmbSDate" readonly="readonly" />
To: <input type="date" name="cmbTDate" id="cmbTDate" readonly="readonly" />
Select All : <input type="checkbox" name="AllData" id="AllData" onclick="mcheck()" checked /> <br /> <br />

</div>

<input type="submit" value="Download" />

</div>
}


Javascript



<script type="text/javascript">
function mcheck() {
if ($('#AllData').not(':checked').length) {
document.getElementById("cmbSDate").readOnly = false;
document.getElementById("cmbTDate").readOnly = false;
$("#AllData").attr('checked', false);

}
else {
document.getElementById("cmbSDate").readOnly = true;
document.getElementById("cmbTDate").readOnly = true;
$("#AllData").attr('checked', true);
}
}
</script>


Controller



 public ActionResult Index(int AgentID, bool AllDates, string DateFrom, string DateTo)
{
SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["Real"].ToString());
SqlCommand cmd = new SqlCommand("SP_rptAgentStatus", cn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@AgentID", AgentID);
cmd.Parameters.AddWithValue("@AllDates", AllDates);
cmd.Parameters.AddWithValue("@DateFrom", DateFrom);
cmd.Parameters.AddWithValue("@DateTo", DateTo);
DataTable dt = new DataTable();
SqlDataAdapter sda = new SqlDataAdapter(cmd);
sda.Fill(dt);

lstatus mls = new lstatus();

Reports.rptAgentStatus rpt = new Reports.rptAgentStatus();
rpt.SetDatabaseLogon("sa", "");
rpt.SetDataSource(dt);
rpt.SetParameterValue(0, "SUKH CHAYN RESIDENCE");
rpt.SetParameterValue(1, "Agent Status "+ DateTime.Parse(DateFrom).ToShortDateString() + DateTime.Parse(DateTo).ToShortDateString());
rpt.SetParameterValue(2, AgentID);
rpt.SetParameterValue(3, DateFrom);
rpt.SetParameterValue(4, DateTo);

Response.Buffer = false;
Response.ClearContent();
Response.ClearHeaders();


Stream str = rpt.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
str.Seek(0, SeekOrigin.Begin);
return File(str, "application/pdf", "rptAgentStatus.pdf");



}









share|improve this question
















I want to pass parameter value but when I click download error show AllDates show null value. Allstate is a checkbox for if check fetches all data if not check then put date from and Date to then fetch value. But All Date value not pass to the controller and show null value. Any expert tells me where I am wrong.



i am sharing error:




The parameters dictionary contains a null entry for parameter
'AllDates' of non-nullable type 'System.Boolean' for method
'System.Web.Mvc.ActionResult Index(Int32, Boolean, System.String,
System.String)' in
'Lead_Management_System.Controllers.ReportController'. An optional
parameter must be a reference type, a nullable type, or be declared as
an optional parameter. Parameter name: parameters




HTML



     @using (Html.BeginForm("Index", "Report"))
{
<div class="form-control">

Agent @Html.DropDownListFor(m => m.agentid, Model.SaleAgentList, new { id = "lblAgent" })


<div id="lblDate">
<br />
Followup Date <br /><br />
From: <input type="date" name="cmbSDate" id="cmbSDate" readonly="readonly" />
To: <input type="date" name="cmbTDate" id="cmbTDate" readonly="readonly" />
Select All : <input type="checkbox" name="AllData" id="AllData" onclick="mcheck()" checked /> <br /> <br />

</div>

<input type="submit" value="Download" />

</div>
}


Javascript



<script type="text/javascript">
function mcheck() {
if ($('#AllData').not(':checked').length) {
document.getElementById("cmbSDate").readOnly = false;
document.getElementById("cmbTDate").readOnly = false;
$("#AllData").attr('checked', false);

}
else {
document.getElementById("cmbSDate").readOnly = true;
document.getElementById("cmbTDate").readOnly = true;
$("#AllData").attr('checked', true);
}
}
</script>


Controller



 public ActionResult Index(int AgentID, bool AllDates, string DateFrom, string DateTo)
{
SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["Real"].ToString());
SqlCommand cmd = new SqlCommand("SP_rptAgentStatus", cn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@AgentID", AgentID);
cmd.Parameters.AddWithValue("@AllDates", AllDates);
cmd.Parameters.AddWithValue("@DateFrom", DateFrom);
cmd.Parameters.AddWithValue("@DateTo", DateTo);
DataTable dt = new DataTable();
SqlDataAdapter sda = new SqlDataAdapter(cmd);
sda.Fill(dt);

lstatus mls = new lstatus();

Reports.rptAgentStatus rpt = new Reports.rptAgentStatus();
rpt.SetDatabaseLogon("sa", "");
rpt.SetDataSource(dt);
rpt.SetParameterValue(0, "SUKH CHAYN RESIDENCE");
rpt.SetParameterValue(1, "Agent Status "+ DateTime.Parse(DateFrom).ToShortDateString() + DateTime.Parse(DateTo).ToShortDateString());
rpt.SetParameterValue(2, AgentID);
rpt.SetParameterValue(3, DateFrom);
rpt.SetParameterValue(4, DateTo);

Response.Buffer = false;
Response.ClearContent();
Response.ClearHeaders();


Stream str = rpt.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
str.Seek(0, SeekOrigin.Begin);
return File(str, "application/pdf", "rptAgentStatus.pdf");



}






javascript c# jquery asp.net-mvc razor






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 2 '18 at 0:40









Nkosi

120k17141206




120k17141206










asked Nov 29 '18 at 6:24









user2697533user2697533

2718




2718








  • 1





    not worked that much on mvc but in my previous company we used to have a hidden field to every radiobutton and use to set the hiddenfield value 1 and 0 and in modal we use bit and the name of the particular hidden field which works fine

    – user10249871
    Nov 29 '18 at 6:28











  • can you share a sample idea a just little bit in this scenario @Ibrahim shaikh

    – user2697533
    Nov 29 '18 at 6:32











  • You're declared bool AllDates as parameter but the checkbox has <input type="checkbox" name="AllData" id="AllData" onclick="mcheck()" checked />, which name attribute of the checkbox doesn't match with action parameter and returns null value. Why not use strongly-typed helpers like @Html.CheckBoxFor?

    – Tetsuya Yamamoto
    Nov 29 '18 at 6:33













  • i don't have model Allstate that's why I am not using strongly-typed @Tetsuya Yamamoto

    – user2697533
    Nov 29 '18 at 6:41














  • 1





    not worked that much on mvc but in my previous company we used to have a hidden field to every radiobutton and use to set the hiddenfield value 1 and 0 and in modal we use bit and the name of the particular hidden field which works fine

    – user10249871
    Nov 29 '18 at 6:28











  • can you share a sample idea a just little bit in this scenario @Ibrahim shaikh

    – user2697533
    Nov 29 '18 at 6:32











  • You're declared bool AllDates as parameter but the checkbox has <input type="checkbox" name="AllData" id="AllData" onclick="mcheck()" checked />, which name attribute of the checkbox doesn't match with action parameter and returns null value. Why not use strongly-typed helpers like @Html.CheckBoxFor?

    – Tetsuya Yamamoto
    Nov 29 '18 at 6:33













  • i don't have model Allstate that's why I am not using strongly-typed @Tetsuya Yamamoto

    – user2697533
    Nov 29 '18 at 6:41








1




1





not worked that much on mvc but in my previous company we used to have a hidden field to every radiobutton and use to set the hiddenfield value 1 and 0 and in modal we use bit and the name of the particular hidden field which works fine

– user10249871
Nov 29 '18 at 6:28





not worked that much on mvc but in my previous company we used to have a hidden field to every radiobutton and use to set the hiddenfield value 1 and 0 and in modal we use bit and the name of the particular hidden field which works fine

– user10249871
Nov 29 '18 at 6:28













can you share a sample idea a just little bit in this scenario @Ibrahim shaikh

– user2697533
Nov 29 '18 at 6:32





can you share a sample idea a just little bit in this scenario @Ibrahim shaikh

– user2697533
Nov 29 '18 at 6:32













You're declared bool AllDates as parameter but the checkbox has <input type="checkbox" name="AllData" id="AllData" onclick="mcheck()" checked />, which name attribute of the checkbox doesn't match with action parameter and returns null value. Why not use strongly-typed helpers like @Html.CheckBoxFor?

– Tetsuya Yamamoto
Nov 29 '18 at 6:33







You're declared bool AllDates as parameter but the checkbox has <input type="checkbox" name="AllData" id="AllData" onclick="mcheck()" checked />, which name attribute of the checkbox doesn't match with action parameter and returns null value. Why not use strongly-typed helpers like @Html.CheckBoxFor?

– Tetsuya Yamamoto
Nov 29 '18 at 6:33















i don't have model Allstate that's why I am not using strongly-typed @Tetsuya Yamamoto

– user2697533
Nov 29 '18 at 6:41





i don't have model Allstate that's why I am not using strongly-typed @Tetsuya Yamamoto

– user2697533
Nov 29 '18 at 6:41












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53533007%2fcheckbox-show-null-value-not-pass-to-controller-mvc%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53533007%2fcheckbox-show-null-value-not-pass-to-controller-mvc%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Contact image not getting when fetch all contact list from iPhone by CNContact

Idjassú

count number of partitions of a set with n elements into k subsets