如何将十进制值传递给Action方法 [英] How to pass decimal value to Action method

查看:78
本文介绍了如何将十进制值传递给Action方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下操作方法

public ViewResult Index()
public ActionResult Edit(decimal id)

当用户单击编辑"链接时,我要调用Edit操作.以下是示例代码段

When user clicks on Edit link, I want to invoke the Edit Action. Following is the sample code snippet

<td>
    @Html.ActionLink("Edit", "Edit", new { id=item.ItemID }) |
    @Html.ActionLink("Details", "Details", new { id=item.ItemID }) |
    @Html.ActionLink("Delete", "Delete", new { id= item.ItemID})
</td>

它重定向到的URL是http://MyServer/Orders/Details/0.020

The URL it redirects to is http://MyServer/Orders/Details/0.020

使用此URL时,不会调用我的操作方法.如果我手动编辑URL以删除."然后我的方法被调用.

With this URL my action method does not invoke. If I manually edit the URL to remove "." then my method gets call.

我的问题是传递十进制值以调用Action方法的正确方法是什么?

My question is what is the right way to pass the decimal value to invoke the Action method?

推荐答案

最好的方法是使用查询字符串将其传递:

The best way to do that is to pass it using query string:

http://MyServer/Orders/Details?id=0.20

您如何定义路线?从路由中删除ID,ActionLink会将其添加为查询字符串.

How did you define your routes? Remove the id from the route and ActionLink will add it as query string.

这篇关于如何将十进制值传递给Action方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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