1

Am new to MVC so please bear with me.

What I'm trying to do is, on page 1 , user enters values into two text fields and on clicking submit button, it will call wcf service and if wcf call returns validated values then it should redirect to different page and display the returned values from wcf call.

I created view like this -

      <input type="text" name="txtUniqueCode" value="@Model.UniqueCode" placeholder="unique identifier" />
            <label for="name">
                Vehicle Registration
            </label>
            <input type="text" name="txtRegistration" value="@Model.Registration" placeholder="Registration" />

            <a href="@Url.Action("ShowRepairDetails", "RepairDetails", new { uniqueCode = Model.UniqueCode, registration = Model.Registration })">Check Status</a>

After user enters values in the textbox's and as soon as he clicks "Check status", am trying to pass the values to the controller using Url.Action. But when I debug and check the parameter values on controller they are coming back to me as null. Am not sure why ??

I tried replacing the parameter values with static values like below in url.Action -

  @Url.Action("ShowRepairDetails", "RepairDetails", new { uniqueCode = 1234, registration = "Test" })

that was working fine, I was receiving the parameter values correctly on controller side. So from what I understood "Model" object is not getting updated even after user enters some values into text box. I'm missing something here. Could you please help..

Thanks in advance
Sai

1 Answer 1

1

It appears that you are misunderstanding the workflow here. The link in you code is calculated by the server before is sends the page to the client. There is no way for it to use the values that the user enters into the text boxes later. To do that, you need a form with a submit action, or an AJAX call that extracts the values of the HTML elements and sends those back to the server.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for replying.. so that means when we use A href with url.action it directly sends to server first for processing without considering the values. just now I tried with Submit button and it worked fine. I will now try with Ajax option..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.