我们如何将值从控制器传递到视图 [英] How can we pass value from controller to view
本文介绍了我们如何将值从控制器传递到视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是MVC 3的新手
我有登录页面,用户名文本框和按钮提交请求。
我通过JQuery调用控制器动作,如下所示
I''m new to MVC 3
I have login page with username textbox and button to submit the request.
I''m calling the controller action through JQuery as shown below
<script type="text/javascript">
$(document).ready(function () {
$(''#btnLogin'').click(function () {
document.location = ''@Url.Action("Validateuser" , "Login")'';
});
$(''body'').css("background", "#517EAD");
$(''body'').css("margin", "0");
});
</script>
<div style="background:white;text-align:right;padding:0px 50px;">
<h2>Please Login</h2>
</div>
<div style="float:right;">
<table border="0">
<tr>
<td>
<label id="lbllogin">LoginID:</label>
</td>
<td>
<input type="text" id="txtLogin" required placeholder="Prashant" style="border-radius:5px;background:orange;"/>
<label style="color:Red;font-weight:bold;">@TempData["Msg"]</label>
</td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" id="btnLogin" value="Login" style="border-radius:15px;background:silver;"/>
</td>
</tr>
</table>
</div>
控制器需要1个参数,如下所示
The controller takes 1 parameter as shown below
public ActionResult Validateuser(string userName)
{
Login objLogin = new Login();
int intUser = objLogin.validateUser();
TempData["Msg"] = "Invalid User";
return RedirectToAction("Index","Login");
}
如何将文本框值传递给控制器?
我有没有其他方式调用控制器,除了我通过jquery做的方式??
任何想法我该怎么办?
谢谢advance
How can i pass textbox value to the controller??
I there any other way to call the controller, apart the way I did through jquery??
Any idea how can i do??
thanks in advance
推荐答案
(document).ready(function(){
(document).ready(function () {
(''#btnLogin'')。click( function(){
document.location =''@ Url.Action(Validateuser,Login)'';
});
(''#btnLogin'').click(function () { document.location = ''@Url.Action("Validateuser" , "Login")''; });
(' 'body'')。css(background,#517EAD);
(''body'').css("background", "#517EAD");
这篇关于我们如何将值从控制器传递到视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文