如何使用asp.net mvc中的按钮传递id [英] How to pass an id using a button in asp.net mvc

查看:89
本文介绍了如何使用asp.net mvc中的按钮传递id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hello guys.am正在开设一个在线录取系统项目,学生可以在线申请入学..



能够将我的申请转到某些阶段,但我是股票。



所以这是我的观点,我必须在我的每个页面上按下,提交按钮响应一个帖子请求,实际保存将数据导入数据库。



但是,当用户将记录保存到数据库中后,我将视图返回给用户以允许它们根据需要进行更改。这也很有效..



现在我的问题,是当我点击另一个按钮让我们说接下来,我想传递studentID到下一页,学生可以填写其他页面并保存他们的记录。

到目前为止,唯一的解决方案是使用重定向操作,但重定向问题,当用户单击提交按钮时会触发,此时,用户无法进行更改根据需要提供表格。



所以我需要下一个按钮来帮助触发事件,将studentID作为url参数传递给我的其他视图..



提前谢谢

hello guys.am working on a project of an online admission system where students can apply online for admission..

Have been able to get my application to a certain stage but am stock.

so here is my scenarion,i have to button on my each of my pages,the submit button responds to a post request which actully saves the data into the database.

However,when a user after a user has finished saving the record into the database,i return the view back to the user to allow them make changes as required.that also works perfectly..

now my issue,is when i click on the other button lets say next,i want to pass along the studentID to the next page,so the student can fill out the other pages and save their records as appropriate.
The only solution have seen so far is to use a redirect action,but the problem with the redirect,it gets triggered when the user clicks the submit button,and when that,the user cannot make changes to the form as required.

so i need the next button to help triggered the event to pass the studentID as a url parameter to my other views..

Thanks in advance

推荐答案

有很多可能的解决方案,你可以使用其中任何一个。它是您的应用程序,您必须定义将在您的应用程序的后端工作的实际逻辑,以使此过程看起来像工作。我会尝试给你一些这些例子,你可以看到哪一个适合你。



如果您正在使用表单,并在提交后将用户重定向到下一页以填写下一个表单。然后使用输入字段对你来说是一个很好的,你可以在表单中嵌入用户的UserID(在你的情况下是学生),作为隐藏的字段。这对用户不可见,但您可以在服务器端使用其值来执行学生特定的操作。看看下面的表格,



There are many possible solutions to this, and you can use any of them. It is your application and you have to define the actual logic that would be working on the back-end of your application to make this process look like working. I would try to give you a few of these examples, you can see for which one would suit you.

If you're using a form, and upon submit you redirect the user to the next page to fill the next form. Then using an input field would be a good one for you, you can embed the UserID of the user (student in your case) inside the form, as a hidden field. Which won't be visible to the user, but you will be able to use its value on the server-side to perform student-specific actions. Have a look at the following form,

<input type="hidden" name="studentID" value="@ValueFromServer" />





ValueFromServer 将由服务器填充并包含UserID。在服务器上,您可以使用此代码访问此值,





The ValueFromServer would be populated by server and would contain the UserID. On the server, you can access this value as this code,

// Match the name of the input field from the form that was submitted
var userId = Request["studentID"];





此外,您可以先允许用户在您的网站上注册,然后使用他们的logged_in状态和他们的ID来执行这些操作(这仍然与上面相同,但仅限于范围价值会增加)。这样,您就可以在应用程序的每个页面上获取学生的UserID。



您也可以将值保存在cookie中, localStorage [ ^ ]或更多方法。这取决于你如何尝试使用它。



切勿在客户端cookie上存储任何敏感信息;如密码,信用卡信息等。



Furthermore, you can first allow the users to register on your website, and then use their logged_in state and their ID to perform these actions (which would be still same as above, but just that the scope of the value would increase). This way you can get the UserID of the student on every page inside your application.

You can also save the values in the cookies, localStorage[^] or many more methods. It depends on how you try to be using it.

Never store any sensitive information on the client-side cookies; such as passwords, credit card information etc.


这篇关于如何使用asp.net mvc中的按钮传递id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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