如何使用锚标记调用我的动作方法,如何在其中传递href url [英] How to call my action method using anchor tag, How to pass the href url in it

查看:51
本文介绍了如何使用锚标记调用我的动作方法,如何在其中传递href url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们



在我的控制器中我有两种动作方法,名称相同但参数不同。





href =url必须调用动作方法



当我想要我的链接给我打电话时动作方法它只调用带有单个参数的方法但在这里我传递了两个参数。

HTTP://本地主机:2290 /帐户/登录模型= Web.Models.LoginModel&安培; RETURNURL = HTTP://本地主机:2290 / [ ^ ]





我的行动方法:

public actionresult login(string Returnurl){} < br $>


另一种方法

公共actionresult登录(MyModelClass模型,字符串Returnurl){}







如何通过网址调用我的动作方法。如果两个参数都是字符串然后我能够调用动作方法,但在这里我有一个参数作为模型,所以当我将模型对象分配给参数我认为我在那里得到一些问题所以请如何传递一个值为型号参数



请帮帮我。!!



提前谢谢

Hi friends

in my controller im have two action methods with same name but with different parameters.


href="url which have to call the action method"

When i am trying to have my link to call my action method it just invoking only the method with a single perameter but here i am passing two parameters.
http://localhost:2290/Account/LogIn?model=Web.Models.LoginModel&Returnurl=http://localhost:2290/[^]


My action methods:
public actionresult login(string Returnurl){}

another method
public actionresult login(MyModelClass model,string Returnurl){}



how can i pass the url for calling my action method. if both parameters are Strings then i am able to call the action method but here i'm having one parameter as model so when i.m assigning model object to the parameter i think there i m getting some issue over there so please how to pass a value for model parameter

please help me out.!!

thanks in advance

推荐答案

一个是HttpGet方法,另一个是HttpPost。

在HttpPost中,您将数据从客户端发布到控制器。这就是为什么该方法有一个模型类型的参数。

现在,如果你想将模型作为参数传递,你需要使用表格。您可以在提交此表单时传递模型值。



请参阅此 -

https://evolpin.wordpress.com/2011/05/09/mvc-和发布数据使用-html-beginform-and-url-routing / [ ^ ]



And关于returnUrl,你可以在@Html.BeginForm()中指定,有点像 -

One is HttpGet method and another one is HttpPost.
In HttpPost you post the data from client side to controller. That's why that method has one parameter of type your model.
Now if you want to pass a model as a parameter, you need to use the form. You can pass the model values on submission of this form.

Refer this-
https://evolpin.wordpress.com/2011/05/09/mvc-and-posting-data-using-html-beginform-and-url-routing/[^]

And about the returnUrl, you can specify that in @Html.BeginForm(), somethng like-
@using(Html.BeginForm("action", "controller", new { returnUrl= "your url" }, FormMethod.Post, null)





-KR



-KR


这篇关于如何使用锚标记调用我的动作方法,如何在其中传递href url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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