mercredi 17 juin 2015

Inherited Property of Model is always returning Null Value

I have a view which displays a radiobutton list on left side of the page and it also loads a partialview on right side of the page which consist of various filters to be selected before displaying a report in a popup window.

The problem is that the property named 'ReportName' always return a Null value when submit button is pressed instead of the returning a string value of selected Radiobutton Other properties such as Branchcode, PeriodFrom, PeriodTo return correctly.

what should i do to get proper string value such as AppointmentSummary, SplcodeRegSummary, or SplcodeReg when its radiobutton is selected.

Thanks in advance for your help.

MODEL:

public class ReportModel
{
    [Required(ErrorMessage = "Please select a Report!")]
    public string ReportName { get; set; }
}

public class ReportFilters :ReportModel         //inherited 
{
    [Required(ErrorMessage="Please select Branch name!")]
    public int BranchCode { get; set; }

    [Required(ErrorMessage = "Please specify 'Period from' date!")]
    [DataType(DataType.Date)]
    public DateTime PeriodFrom { get; set; }

    [Required(ErrorMessage = "Please specify 'Period to' date!")]
    [DataType(DataType.Date)]
    public DateTime PeriodTo { get; set; }
}

CONTROLLER:

public ActionResult MIS1()
{
    ViewBag.Branch = (from c in BranchList().AsEnumerable()
                      orderby c["BranchName"]
                      select new { BranchCode = c["BranchCode"], BranchName = c["BranchName"] }).ToList();

    return PartialView();
}


public ActionResult MISPopup(ReportFilters rf)
{
    if (ModelState.IsValid)
    {
        return View(rf);
    }
    return View();
}

VIEW:

<TABLE>
<TR>
<td>
    @Html.RadioButtonFor(model => model.ReportName, "AppointmentSummary", new { id = "AppointmentSummary" })
    @Html.Label("AppointmentSummary", "Appointment Summary")<br />

    @Html.RadioButtonFor(model => model.ReportName, "SplcodeRegSummary", new { id = "SplcodeRegSummary" })
    @Html.Label("SplcodeRegSummary", "Special codewise Registration summary")<br />

    @Html.RadioButtonFor(model => model.ReportName, "SplcodeReg", new { id = "SplcodeReg" })
    @Html.Label("SplcodeReg", "Special codewise Registrations")<br />
</TD>
</TR>

<TR>
<TD>
    @Html.Partial("~/Views/Shared/ReportFilters.cshtml")
</TD>
</TR>
</TABLE>

PARTIAL VIEW:

@model MVCProject.Models.ReportFilters
@using (Html.BeginForm("MISPopup", "MIS", FormMethod.Get, new { target = "_blank" }))
{ 
<div >
    <table width="100%">
        <tr>
            <td>
                @Html.HiddenFor(model => model.ReportName)
                @Html.Label("ClinicBranch", "Clinic Branch")
            </td>
            <td colspan="3">
                @try
                {
                    @Html.DropDownListFor(model => model.BranchCode, new SelectList(ViewBag.Branch, "BranchCode", "BranchName"), "--Select Branch--")
                }
                catch (Exception e)
                {
                    @Html.DropDownList("Branch", new SelectList(string.Empty, "Value", "Text"), "--Select Branch--")
                }
                @Html.ValidationMessageFor(model => model.BranchCode)
            </td>
        </tr>

        <tr>
            <td>
                @Html.Label("FromDate", "From date")
            </td>
            <td>
                @Html.EditorFor(model => model.PeriodFrom)
                @Html.ValidationMessageFor(model => model.PeriodFrom)
            </td>
            <td>
                @Html.Label("ToDate", "To date")
            </td>
            <td>
                @Html.EditorFor(model => model.PeriodTo)
                @Html.ValidationMessageFor(model => model.PeriodTo)
            </td>
        <tr><td colspan="4"><br /></td></tr>
        <tr>
            <td colspan="4" style="text-align:center;">
                <input type="image" id="submit" value="View"  src="~/Images/View.png" />
            </td>
        </tr>
    </table>
</div>
}

Aucun commentaire:

Enregistrer un commentaire