0

внутри он есть, но на страницу не выводится
как выглядит дебаг
рисунок из дебага

как выглядит в браузере
отображение на форме
класс для хранения значений

public class Calculator
{
    private double a;
    private double b;
    private double res;

    public double A
    {
        get
        {
            return a;
        }

        set
        {
            a = value;
        }
    }

    public double B
    {
        get
        {
            return b;
        }

        set
        {
            b = value;
        }
    }

    public double Res
    {
        get
        {
            return res;
        }

        set
        {
            res = value;
        }
    }
}

страница cshtml

@{
ViewBag.Title = "Index";
}

@model ASPMVCLesson4.Models.Calculator

<h2>Index</h2>

@using (Html.BeginForm())
{
    @Html.TextBoxFor(m => Model.A);
    @:
    @Html.TextBoxFor(m => Model.B);
    @: =
    @Html.TextBoxFor(m => Model.Res);
    <br />
    <input type="submit" value="+" name="action:Add" id="Add" />
    <input type="submit" value="-" name="action:Sub" id="Sub" />
    <input type="submit" value="*" name="action:Mul" id="Mul" />
    <input type="submit" value="/" name="action:Div" id="Div" />
}

код контролера

// GET: Home
    public ActionResult Index()
    {
        return View();
    }

    [HttpPost]
    [MultiButton(Name = "action", Argument = "Add")]
    public ActionResult Add(Calculator calc)
    {
        calc.Res = calc.A + calc.B;
        return View("Index", calc);
    }

    [HttpPost]
    [MultiButton(Name = "action", Argument = "Sub")]
    public ActionResult Sub(Calculator calc)
    {
        calc.Res = calc.A - calc.B;
        return View("Index", calc);
    }

    [HttpPost]
    [MultiButton(Name = "action", Argument = "Mul")]
    public ActionResult Mul(Calculator calc)
    {
        calc.Res = calc.A * calc.B;
        return View("Index", calc);
    }

    [HttpPost]
    [MultiButton(Name = "action", Argument = "Div")]
    public ActionResult Div(Calculator calc)
    {
        calc.Res = calc.A / calc.B;
        return View("Index", calc);
    }
}
2
  • Попробуйте вот тут @: = убрать знак =
    – Andrei S.
    18 авг 2017 в 13:03
  • @AndreiS.убрал. все тоже самое
    – Alexandr
    18 авг 2017 в 13:58

1 ответ 1

-1

Да проблема может быть в том что нет SET или @ вот с этими штуками.

Да и вообще лучше используй public int Value {get; set;}

Это же всё таки контракт. А если и насетапят каким то образом и отправят, то ты же можешь проверить на back end side. Тут нестоит заморчиватся и клепать private и определять get; set;

1
  • в классе есть и get и set.
    – Alexandr
    22 авг 2017 в 6:07

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.