In both JavaScript and VB.NET, it is important to note that the expression does not yield a value

Within the Create View for the "Deal" model, I have implemented a JavaScript function that is intended to generate a new object within a List Property when a specific button is clicked.

The error message "expression does not produce a value" has appeared. I am confused by this as I do not require a value; my objective is simply to create an empty object within the list.

Specifically, the line in the JavaScript of my view which adds the new Period to the list is triggering the error:

<script type="text/javascript">
    function addRow() {
        @Model.Periods.Add(New DealPeriod());
        ...
    }
</script>

Details of the "Deal" Model:

Public MustInherit Class Deal

    ...

    <Display(name:="Periodos")>
    Public Property Periods As New List(Of DealPeriod)

Answer №1

Addressing two key issues here which are crucial for resolving the problem mentioned in the question regarding "expression does not produce a value":

When you see the @ symbol in this context, it signifies to "output the result of the following to the http response stream".

Since List.Add() does not return a value (void), there is no data to send to the response stream, resulting in that particular error message.

In simpler terms, the @ requires a value, and List.Add() doesn't provide one.

The second issue highlighted here suggests a potential mix-up between server-side execution and client-side execution (not to be confused with server-side/client-side code, which can coexist as demonstrated). It seems like an attempt to add a new "DealPeriod" when "addRow" is triggered - but that's not how it functions. VB.Net code operates on the server side, while JavaScript code runs on the client side (the browser), operating independently from each other.

To establish a connection between them, options such as using an ajax call or signalr can be explored.

Answer №2

When you expect

@Model.Periods.Add(New DealPeriod());
to be executed upon calling the javascript function, it doesn't actually happen as expected. This is because the inline VB code runs on the server-side before the HTML is sent to the client. To see the rendered code in that javascript function, open your webpage and view its page source. You will notice that the specific line of code is not included. Instead, what you should do is make an ajax call to a controller that will handle the desired logic.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Three.js - Exploring Camera Rotation and Transformations

I have a three.js scene where I can add and edit objects. Recently, I added a checkbox for "Rotate Camera" which is working well. However, the issue I am facing is that the transformControls attached to the object seem to rotate differently: when I stop th ...

Let's update the VUE app's development server to point to my-testing-web-address.com instead of the default localhost:

I am working on a VUE application and I am trying to run it on an external link instead of localhost. I attempted to configure a vue.config.js devServer: { host: 'http://my-testing-web-address.com', port: 8080, ... } and adjusted t ...

What is the best way to retrieve information from a data set?

After borrowing some basic HTML, CSS, and JavaScript code from CodePen, I ran into an issue while attempting to convert it to React. The error message says that it cannot read properties of null (specifically 'dataset'). Here is the JavaScript c ...

Inconsistent behavior between Chrome and Firefox when using AngularJS $resource GET method: success in Chrome but error

I am currently working on a simple custom GET request in Angular using $resource angular.module('myApp') .factory('MyService', function($resource){ return $resrouce('some url', {}, { list: {method:'G ...

"Error occurs when passing data back to main thread from a web worker: undefined data received

Hello, I’ve been experimenting with using a web worker to retrieve data and send it back to the main thread. However, I've encountered an issue with my code not working as expected. onmessage = (e) => { console.log(e); if( e.data[0] === &apos ...

Tips and Tricks for Uploading Images with React, fetch, and Django REST

Currently facing a roadblock in my development work. Attempting to upload a photo through FormData in fetch, but running into issues with the content header or backend handling. Need some assistance troubleshooting this problem. general.js - Handler for r ...

Modify the background color of a menu item when hovering, without displaying the submenu in WPF

I am facing some issues with the menuitem in WPF. I am trying to change the background color of the menu item when I hover over it. I have managed to do that, but now the submenu in the menu item is not showing. Please help me understand why and fix it if ...

CombineReducers takes all the reducer content and unpacks it into a single reducer

As I work on developing a small application, I am contemplating the best strategy for organizing reducers within it. My objective is to retrieve JSON data from the application state and structure it as shown below: { "fruits": [ {"appl ...

Combining numerous objects into one object within an array, each with distinct keys, and displaying them using FlatList

I'm struggling to present this information in a FlatList. Array [ Object { "-N1gqvHXUi2LLGdtIumv": Object { "Message": "Aeaaeaea", "Message_CreatedAt": 1652167522975, "Message_by_Ema ...

Sending a parameter as text from .NET code-behind to a JavaScript function

So here's the situation: I have a gridview that is displayed in a new window separate from the parent window. This gridview contains multiple records, each with a "view" button that allows users to see more details about the record within the same new ...

Error thrown by Jest: TypeError - req.headers.get function is not defined

I have a function that is used to find the header in the request object: export async function authorizeAccess(req: Request): Promise<Response | {}> { const access = req.headers.get('Access') if(!access) return Response.json('N ...

Loading images in advance before webpage loads

Welcome friends! This is my first time asking a question here, so I hope I'm doing it right :) I'm looking to preload 3 images before the webpage fully loads so that they all appear simultaneously. Currently, the images load one after another and ...

Issue with generating PDF in AngularJS: pdfMakeTypeError occurs due to inability to read 'ownerDocument' property within html2canvas

Whenever I try to export by clicking the export button, this code is triggered: $scope.export = function() { html2canvas(document.getElementById('balanceSheet')).then(function(canvas) { document.body.appendChild(canvas); ...

Hide the scrollbar on an iframe

I have been trying to modify the attributes of an iframe using javascript in the following way: var iFrame = window.top.document.getElementById('window_content'); iFrame.setAttribute("height","63"); iFrame.setAttribute("scrolling","no") ...

Node.js 'BLOB containing [object File]'

I am currently attempting to retrieve a BLOB from a request. The request object is created using FormData in Angular. const buffer = fs.readFileSync(fileFromRequest); The above code is resulting in an error: Error: ENOENT: no such file or directory, ope ...

When initially loaded, the Bootstrap Datepicker displays an inaccurate calendar

I implemented Bootstrap Datepicker to insert a date input field into my HTML document. Below is the code I used: HTML: <input type="text" name="manifest-date" class="calendar form-control" placeholder="M-d-yy" id="manifest-date" value="{{$currentDate} ...

Creating a variable in JavaScript

In my HTML body, I have set up a global variable named index with the value <%var index = 0;%>. This allows me to access it throughout the code. I'm trying to assign the value of $(this).val() to <% index %>, but I can't seem to get ...

Tips for managing the second datepicker for the return journey on Abhibus using Selenium webdriver

I am currently working on a code to choose departure date and return journey date, but I am encountering an issue where the return journey date is not being selected. The driver seems to be skipping over the return date selection and proceeding directly to ...

Creating a custom video to use as the favicon for my website

Imagine this: With the help of this plugin, you can have a video playing as your site's favicon using the following code snippet: var favicon=new Favico(); var video=document.getElementById('videoId'); favicon.video(video); //stop favicon.v ...

JavaScript code to verify if a checkbox is selected

Having some trouble making a text box value change based on checkbox status. I've attached a function to the onclick event of the checkbox, but it's not quite working as expected. <div> MyCheckbox <input type="checkbox" id="Check1" name ...