0
votes

I m trying to get a list of radiobuttons from the controller and display it on the View but it dosent seem to be working. I have the following model

public class Module
{

    public int ModuleId { get; set; }

    public string Title { get; set; }

    public string Description { get; set; }

    public bool IsActive { get; set; }

}

In the controller I am getting the list of modules and passing it to the view:

[HttpGet]
    public ActionResult SelectAdmin()
    {
        //getting the list of modules from db
        List<Module> modulelst = GetModules(); 
        ViewBag.lstm = modulelst;

        return PartialView();
    }

Now in the View I'm trying to display the list of modules in the form of RadioButtons/Checkboxes and getting the corresponding id for the module which is selected.

The code for the View I am trying is as follows:

@model List<MyFriday.Domain.Model.Client>

@using (Ajax.BeginForm("SelectAdmin", "CMAdmin", null, new AjaxOptions { UpdateTargetId = "update-message", InsertionMode = InsertionMode.Replace, HttpMethod = "POST", OnSuccess = "UpdateSuccess" }, new { @id = "EditForm" })) { @Html.ValidationSummary(true)

<fieldset>

<div class="content">                     
            @using (Html.BeginForm())
            {
                <div>
                Select the Admin Type:
                 </div>
                <div id="divModules">
                @foreach (var Modules in ViewBag.lstm)
                {
                    <div class="formlabel">
                        <div align="right" class="label" style="cursor: pointer; position: relative;">
                            @(Modules.First().Title)
                        </div>
                    </div>
                    <div class="formelement">
                        <input type="radio" id=""/>
                            @(Modules.First().ModuleId)

                    </div>
                    <div style="clear: both;">
                    </div>
                }
                </div>
                <input id="Submit1"  type="submit" value="Submit"/>
                <input type="button" value="Cancel" onclick="javascript:cancelconfirm(this)"/>   

            }
            <div style="clear: both;">
                &nbsp;</div>

        </div>

</fieldset> 

}

The Above View is not getting displayed

Can anyone please suggest me a solution ?

1
The View is not getting display at allNealCaffrey
Looks like the error is in the view, you can use Fiddler2 to see what the error message is and post it here which will be useful.Darren
@Darren Davies : Fiddler2 dosent debug .cshtml page I guess ??NealCaffrey

1 Answers

0
votes

First I would change the controller:

[HttpGet]
public ActionResult SelectAdmin()
{
    //getting the list of modules from db
    List<Module> modulelst = GetModules(); 
    // ViewBag.lstm = modulelst;

    return PartialView(modulelst);
}

Then change the View... add the decalration it uses the model on the first line:

@model List<Module>

and then change the for loop to:

            @foreach (var module in Model)
            {
                <div class="formlabel">
                    <div align="right" class="label" style="cursor: pointer; position: relative;">
                        @Html.DisplayFor(modelItem => module.Title, true)

                    </div>
                </div>
                <div class="formelement">
                    <input type="radio" id=""/>
                        @RadioButtonFor(modelItem => module.ModuleId, new { @id="ModuleId"})

                </div>
                <div style="clear: both;">
                </div>
            }