0

请帮助我 。我写了这个剃刀代码:

@using (Html.BeginForm("send", "default", FormMethod.Post))
{
    <input type="text" id="txtNumber" />
    <input type="submit" value="submit 1" />
    <input type="submit" value="submit 2" />
}

控制器代码:

[HttpPost]
    public HtmlString send(FormCollection frm)
    {
        string _data = frm["txtNumber"];
        //
        // HOW ? if submit 1 clicked       _data + "x" = result
        //
        // HOW ? if submit 2 clicked       _data + "y" = result
        //
        return new HtmlString(_data);

    }

但是这个错误:(异常详细信息:System.NullReferenceException:对象引用未设置为对象的实例。> string _data = frm [“txtNumber”] ;。Tnqs请帮助!

4

1 回答 1

0
@using (Html.BeginForm("send", "default", FormMethod.Post))
{
    <input type="text" id="txtNumber" />
    <button type="submit" name="btn" value="btn1">submit 1</button>
    <button type="submit" name="btn" value="btn2">submit 2</button>
}

进而:

[HttpPost]
public HtmlString send(FormCollection frm)
{
    string _data = frm["txtNumber"];

    string btn = frm["btn"];
    if (btn == "btn1")
    {
        // submit 1 was clicked
    }
    else 
    {
        // submit 2 was clicked
    }

    return new HtmlString(_data);
}
于 2013-07-05T06:14:07.903 回答