0

The problem I am having is that the Custom Model Binder is null when I try to retrieve by GetValue("Budget") but as you can see, the binder contains the prefix. I also get all the keys if I look in the metadata i have them there, but still NULL. Anyone can explain why I am getting NULL ?

My View > List.cshtml

for (var i = 0; i < Model.Budget.BudgetRader.Count; i++)
    {

        if (Model.Budget.BudgetRader[i].Konto != -1) { 
               <tr id="@Model.Budget.BudgetRader[i].RadNr1 +'-'+ @Model.Budget.BudgetRader[i].RadNr2 +"-"+ @Model.Budget.BudgetRader[i].RadNr3">        
                   <td>@Html.TextBoxFor(m => Model.Budget.BudgetRader[i].BudgetBelopp)</td>
               </tr>}
    }

My ViewModel > BudgetListViewModel

public class BudgetListViewModel
{        
    public Budget Budget { get; set; }

    public IList<BudgetRad> BudgetRaderList { get; set; }        
}

My Custom Model Binder > BudgetListModelBinder

    public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
    {


        //var budgetListViewModel = (BudgetListViewModel) bindingContext.Model;

        //true
        var exists = bindingContext.ValueProvider.ContainsPrefix("Budget"); 

        // gives null
        var tmp = bindingContext.ValueProvider.GetValue(bindingContext.ModelName); 

        // gives null
        var tmp2 = controllerContext.HttpContext.Request.Form.Get("Budget"); 


    }

Globalasa

private void RegisterModelBinders()
    {
        ModelBinders.Binders.Add(typeof(BudgetListViewModel), new BudgetListModelBinder());
    }
n3tx
  • 429
  • 2
  • 10
  • 23

0 Answers0