Error while publishing code in View which has its controller return value JsonResult

Santosh Umarani 81 Reputation points
2022-02-01T12:25:44.027+00:00

Hi,

I have added the following code in controller in which I am returning JsonResult and I am having this code in existing view that is :

[HttpPost]
public JsonResult GetVersionNumber(string testTypeName)
{
return Json(allowedVersion);
}

In View, I am having the following ajax function.

$('#testTypeName').change(function () {
$.ajax({
url: '/TestCases/GetVersionNumber',
type: 'POST',
data: { "testTypeName": $('#testTypeName').val() },
dataType: 'JSON',
success: function (json, response) {
...
...
}
});
});

The code is perfectly fine in local machine. However, when I try to publish it, I am getting the error "Copying file Views\TestCases\GetVersionNumber.cshtml to obj\Release\AspnetCompileMerge\Source\Views\TestCases\GetVersionNumber.cshtml failed. Could not find file 'Views\TestCases\GetVersionNumber.cshtml'."
Since in URL ,I am passing "'/TestCases/GetVersionNumber'" its expecting a view with the name GetVersionNumber. I dont to have another view created for this.
Please do let me know if we can have ajax function without URL or any other way to achieve this functionality

Kindly waiting for your response.

Thanks,
Santosh

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,237 questions
0 comments No comments
{count} votes

Accepted answer
  1. Yijing Sun-MSFT 7,061 Reputation points
    2022-02-02T02:40:14.03+00:00

    Hi @Santosh Umarani ,
    First,you need to check if the file is inside the folder. And then you need to tell Visual Studio that you deleted the files.

    Go to the project/solution folder where the files existed and remove them there.

    Visual Studio assumes that since you added the file originally, it should be published. It can't assume that you don't want it just because it isn't in the file system. Think about using source control in a team - the file may only exist in one persons's machine, but still be needed.

    This is not a difficult as you think - the files that can not be found have a semi-transparent look to them, easy enough to select these and bulk delete in Visual Studio. You can also set the project properties to display all files then select all the ones that need to be part of the project and add them in a single operation.

    Best regards,
    Yijing Sun


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our  documentation  to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Santosh Umarani 81 Reputation points
    2022-02-02T04:50:36.073+00:00

    Thank you YijingSun-MSFT. Its working fine now

    0 comments No comments