简体   繁体   中英

What's the equivalent of this PHP code for ASP.NET, is there any?

I'm pretty new to ASP.NET/MVC/Razor and have been raking my brain about how to (logically) convert a PHP concept to ASP.NET. It might not be possible but I'm not sure and yes, I know it certainly isn't nice code.

Essentially what I'd like to do is handle a multi step/stage form. In my case it's to configure some permissions on a system. For this I have to do these steps:

  • Select a User (Front end)
  • Get a List of Elements for that User (Back end)
  • List the Elements of that User (Front end)

With PHP (simplified) I could do something like this:

<?php
include("collectinformation.php");
$data = null;
if($_GET['step'] == 2 && isset($_POST['user'])){
    // Collect list of elements for a user selected in step 1
    $data = collectinformation($_POST['user']);
}
?>

<form action="form.php?step=2" method="post">
  <input type="text" name="user">
  <input type="submit">
</form>

<form action="changepermission.php" method="post">
<?php
foreach($data as element){
    echo '<input type="text" name="'.$element['name'].'" value="'.$element['value'].'">';
}
?>
  <input type="submit">
</form>

The real problem I'm trying to counter with this is to serve a variety of forms using a generic controller while the forms might also need custom code. If the above serves as an example I don't have any problem to implement the $_GET['step'] == 2 part to make the transfer from the view without the list to the one with the list but I don't know how/where I'd implement the code for collectinformation if I'd want to avoid the compilation of the whole project. Usually this would be part of the model for that one specific form/process. From my current View this would mean I'd have to extend the Model of the project and recompile it afterwards. Is there an option to have that particular piece of code either in it's own module and dynamically load it or is it possible to just have that code in the .cshtml file for second step directly? It would have the benefit of JIT compilation which would make it easier to change but slower.

I do get the feeling that this would be wrong approach (especially with MVC) but it would make certain tasks easier for me. We have a lot of processes that have pretty unique requirements when it comes to the kind of steps they involve and the interface needed for them and it would be nice to be able to work on them without recompiling the whole project and deploying it again.

The answer seems to be that it's not possible to convert the concept easily. As highlighted by the comments.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM