Click here to Skip to main content
15,881,861 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have one partial view. I am rendering that view on ajax call of checkbox click event. User will enter the values in partial view's textbox and will click on passed button. Issue is that sometime I am able to get the textbox value on controller sometimes not. I am really not able to understand what is going wrong. I am using simple html.BeginForm method on view page to post all the data from view to controller.

This is the controller action:
C#
[HttpPost] 
public ActionResult SetTransaction(UserBOM) { 
  if (
       (UserBOM.CompletedResponse != null && ReasonName == "Contacted")
       || UserBOM.IdEnable == true
  ) {
    TempData["IdEnable"] = UserBOM.IdEnable;
    TempData["ApplicantId"] = UserBOM.ApplicantId;    // intermittent not getting value.
    TempData["ApplicantNumber"] = UserBOM.ApplicantNumber;
    TempData.Keep("IdEnable"); 
    TempData.Keep("ApplicantId");
    TempData.Keep("ApplicantNumber"); 
  }
}

And the view
HTML
@using (Html.BeginForm("SetTransaction", "BranchUser", FormMethod.Post)) {
  //  partial view rendered through ajax call
}

The problem that I am seeing is "In SetTransaction(UserBOM) method, userBOM is getting null. Sometimes it is working as expected but not always. What could be the reason. Thanks."

What I have tried:

I am not able to reproduce it every time as its intermittent issue and really finding difficult to fix this issue.
Posted
Updated 28-Sep-18 5:17am
v2
Comments
F-ES Sitecore 27-Sep-18 6:41am    
Well there isn't a problem with the MVC framework intermittently sending data so the issue is somewhere in your implementation, your environment, or the data you are sending. As you haven't even shown the code it's hard for anyone to advise.
Telstra 27-Sep-18 7:02am    
Controller method to read the data after post.

[HttpPost]
public ActionResult SetTransaction(UserBOM)
{

if ((UserBOM.CompletedResponse != null && ReasonName == "Contacted") || UserBOM.IdEnable == true)
{

TempData["IdEnable"] = UserBOM.IdEnable;
TempData["ApplicantId"] = UserBOM.ApplicantId;//these values I am not getting each time.
TempData["ApplicantNumber"] = UserBOM.ApplicantNumber;
TempData.Keep("IdEnable");
TempData.Keep("ApplicantId");
TempData.Keep("ApplicantNumber");
}

}

This is view file code to post the data to controller
@using (Html.BeginForm("SetTransaction", "BranchUser", FormMethod.Post))
{

//partial view rendered through ajax call
}
Telstra 27-Sep-18 7:07am    
In SetTransaction(UserBOM) method, userBOM is getting null. Sometimes it is working as expected but not always. What could be the reason. Thanks.

1 solution

Quote:
really finding difficult to fix this issue.


It's much more harder for us to help you if you didn't provide how you are sending the data. How do you populate your UserBom object? You should start looking at that code first before going to your MVC Action method to reference the UserBom object.

On a side note, always check for null before referencing a property from your object to avoid unexpected errors.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900