请帮助我在这里我无法确定,我在哪里做错了,我是mvc的新手 [英] Could please help me out here i'm unable to identify, where i have done, mistake, i'm new to mvc

查看:61
本文介绍了请帮助我在这里我无法确定,我在哪里做错了,我是mvc的新手的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现post动作,我将文本框值传递给action,但是我得到了Null值,请在这里帮助我。



i want to implement the post action, I'm passing the text box value to action, but I'm getting getting the Null value, please help me here.

//my contoller
     // GET: EditClient
    [HttpGet]
        public ActionResult VisaEdit()
        {
            return View();
        }

 [HttpPost]
         public ActionResult VisaEdit(String VisaTrackingID)//In this parameter i'm getting the null value
        {
          }







//My view

 @using(Html.BeginForm("VisaEdit","VisaInfo",FormMethod.Post))
         { 
                <input type="text" Id="VisaTrackingID" class="VisaTrackingNo" value="" /> <input type="submit" Id="BtnSearch" value="Search" />
         }     





我尝试了什么:



我将textBox值传递给参数,但该参数显示空值,请在此帮助我,或任何其他方式来实现此目的。



What I have tried:

I'm passing the textBox value to action through the parameter, but that parameter is showing me the null value, please help me here, or any other way to achieve this.

推荐答案





试试这段代码:



@using(Html.BeginForm(VisaEdit,VisaInfo,FormMethod.Post) )

{

< input type =textname =VisaTrackingIDid =VisaTrackingIDclass =VisaTrackingNo/> < input type =submitid =BtnSearchvalue =Search/>

}



这将解决你的问题问题。



原因:



需要有一个名字属性,在你的案例中是VisaTrackingID。



模型绑定器将匹配VisaEdit操作的参数VisaTrackingID,这就是为什么参数需要命名完全相同的原因。


谢谢,

Parveen Siwach
Hi,

Try this code:

@using (Html.BeginForm("VisaEdit", "VisaInfo", FormMethod.Post))
{
<input type="text" name="VisaTrackingID" id="VisaTrackingID" class="VisaTrackingNo" /> <input type="submit" id="BtnSearch" value="Search" />
}

This will solve your problem.

Reason:

needs to have a name attribute, in your case VisaTrackingID.

The model binder will match this to the parameter VisaTrackingID of the VisaEdit action, that is the reason why the parameter needs to be named exactly the same.

Thanks,
Parveen Siwach


你好,

使用name属性而不是VisaTrackingID的id属性,然后尝试。

参考: 这里



谢谢
Hello ,
Use "name" property instead of "id" property of VisaTrackingID and then try .
Refer : Here

Thanks


尝试使用以下代码:



查看代码

Try with below code:

View code:
@using (Html.BeginForm("VisaEdit", "Home", FormMethod.Post))
{
    <input type="text" id="VisaTrackingID" name="VisaTrackingName" class="VisaTrackingNo" value="" />
    <input type="submit" id="BtnSearch" value="Search" />
}



控制器代码


Controller code:

[HttpPost]
public ActionResult VisaEdit(string VisaTrackingName)//In this parameter i'm getting the null value
{
	// You can access value in VisaTrackingName variable
	return View("Index");
}







如果您的表单中有多个控件,那么您可以使用 FormCollection 如下所示:


or

If you have multiple controls inside your form then you can use FormCollection like below:

[HttpPost]
public ActionResult VisaEdit(FormCollection fc)//In this parameter i'm getting the null value
{
	string temp = fc["VisaTrackingName"].ToString();
	return View("Index");
}


这篇关于请帮助我在这里我无法确定,我在哪里做错了,我是mvc的新手的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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