0

I have the partial view .cshtml page as

$("#btnsearch").click(function () {
    dserial = $("#dserial").val();
    $('.content').load("/ServiceMaintenance/SearchInstallationDeviceDetails");
})

Here "dserial" is the id of text box, "btnsearch" is the id of the button and "content" is the id[class] of a div to which the partial view is to be loaded.

My need is to assign the value of 'dserial' to a readonly textbox (let the id be "serialno") in the view SearchInstallationDeviceDetails.cshtml which is in the Controller "ServiceMaintenance"

2
  • 1
    Are you able to change the action parameters? The easiest option is to pass the dserial value to the controller's action and have the partial view already have field read-only. If not, then you just need to look at the complete param of $.load. Let us know which you can do for a viable answer. Commented Sep 1, 2015 at 11:52
  • How can i store dserial temporarly and that value is assigned to the textbox in other view.? @freedomn-m Commented Sep 1, 2015 at 12:00

2 Answers 2

1

1 Change the action parameters, assuming a controller action:

public ActionResult SearchInstallationDeviceDetails()

change to

public ActionResult SearchInstallationDeviceDetails(string dserial)

(or int/guid if string is not appropriate)

then change your js to pass the parameter:

$('.content').load(
              "/ServiceMaintenance/SearchInstallationDeviceDetails",
              { dserial : dserial });

Note: this only works if it's a simple ID, if it's not a simple ID you'll have to use POST

then update your partial view's viewmodel to pass dserial and in the view:

@Html.TextBoxFor(model=>model.dserial, ...

2 Inject the value after the partial has loaded.

Not as nice, but depends on your restrictions (eg if you can't change the controller). You might get a sort of FOUC (flash of unstyled content) - in this case 'un-entered'content

$('.content').load(
          "/ServiceMaintenance/SearchInstallationDeviceDetails",
          function() {
              $("#serialno").val(dserail).prop("readonly", true);
          });
Sign up to request clarification or add additional context in comments.

Comments

0

Could you fill it in after the content has loaded like this?

$('.content').load("/ServiceMaintenance/SearchInstallationDeviceDetails",
function() {
  $('.content #serialno').val(dserial);
});

Comments

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.