MVC 4提交按钮不会发布texboxfor<>值为[httppost]方法 [英] MVC 4 submit button doesn' t post texboxfor<> values to [httppost] method

查看:85
本文介绍了MVC 4提交按钮不会发布texboxfor<>值为[httppost]方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

when i click submit button in my actionresult get invoked but parameters are all empty in model which is models.Soru named as form.

it sends all properties like in my Soru() constructer. Empty string or 0 if int. textboxfor<> cant post values even i edit textbox values on view. I started a new project to try it and with a simple class and view i submit form and when i debug i get into httpPost methot but just nothing in posted class. i can get form with formcollection but i want regular mvc way. 

public ActionResult Index(Models.Soru form) on this line i want form to have class properties with edited textboxfor values but it gets nothing.

does anyone have idea?













public class Soru
{
    public int ID;
    public string Ad;
    public string SoruIcerik;
    public string Cevap;
    public int Sira;

    public Soru()
    {
        ID = 0;
        Ad = string.Empty;
        SoruIcerik = string.Empty;
        Cevap = string.Empty;
        Sira = 0;
    }
}





//这里是控制器





//here is controller

[ValidateInput(false)]
[HttpPost]
public ActionResult Index(Models.Soru form)
{

    return null;
}



//并查看




// and view

@model x.Models.Soru
@{


using (Html.BeginForm())
{
    <div class="col-md-7">

        @Html.TextAreaFor(m => m.SoruIcerik, new { @name = "soruIcerik", @id = "soruIcerik", @rows = "10", @cols = "80" })

    </div>
    <div class="col-md-5">
        <div class="col-md-4 formSatiri">
            <label class="formSatiri">
                Soru Adi :
            </label>
        </div>
        <div class="col-md-8">
            @Html.TextBoxFor(m=>m.Ad, new { @class = "formSatiri" })
        </div>
        <div class="col-md-4 formSatiri">
            <label class="formSatiri">
                Cevap :
            </label>
        </div>
        <div class="col-md-8">
            @Html.TextBoxFor(m => m.Cevap, new { @class = "formSatiri" })
            </div>
        <div class="col-md-12 formSatiri">
            <input type="submit" class="btn btn-primary btn-sm pull-left" value="Kaydet"/>
        </div>
    </div>
}

}

推荐答案

您可以尝试将动作提供到@using表单本身。

@using(动作,控制器,......)



else, Java脚本文件中的


点击按钮进行ajax调用。对于输入类型,给一个idsubmitForm假设7给@ using,html.BeginForm一个idformToBeSubmitted假设。

然后在JS中,
You can try with providing the action into the @using form itself.
@using("Action","Controller",...)

else,
in the Java Script file,
make an ajax call on click of the button. To the input type, give an id "submitForm" suppose 7 give the @using,html.BeginForm an id "formToBeSubmitted" suppose.
Then in the JS,


(#submitForm)。live('click',function(){
("#submitForm").live('click',function(){


.ajax({

类型:POST,

url:控制器/动作,

数据:
.ajax({
type:"POST",
url:"controller/action",
data:


这篇关于MVC 4提交按钮不会发布texboxfor&lt;&gt;值为[httppost]方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆